Tag: uicollectionview

呈现UICollectionView时防止UICollectionViewCellanimation外观

当用户做了一些动作,我需要从底部拉起一个UICollectionView到一定的高度。 由于这个新状态是完全可选的,因此集合视图就在这样呈现之前被创build。 从底部到顶部的animation是通过改变NSLayoutConstraint的constant属性和在一些animation块中调用[view layoutIfNeeded]来实现的。 问题在于,这样做会使单元格以不希望的方式出现:从左上angular扩展到指定的大小。 我希望集合视图能够出现,并且所有的单元格都已经按照最终的大小和外观进行布置。 我知道像UIView的setAnimationEnabled:方法,但我似乎无法find如何以及在哪里我应该使用(如果这是要走的路)。 我猜这个问题是由于集合视图单元格被添加到包含对[superview layoutIfNeeded]的调用的animation块之前的视图层次结构中。 这可能会导致UIKit认为它也应该dynamic改变布局。 如果是这种情况,解决scheme可能是沿着从animation中排除的方式,视图层次结构的特定改变。

无法获取UICollectionView以显示单元格

我试图让一个UICollectionView显示在一个模态的视图控制器。 该应用程序是为iPad的iOS 7。 我已经创build了UIViewController的子类(用一个笔尖),并像这样添加它: MyViewController *controller = [[MyViewController alloc] init]; UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller]; navController.modalPresentationStyle = UIModalPresentationFullScreen; navController.navigationBar.barStyle = UIBarStyleBlackTranslucent; [self presentViewController:navController animated:YES completion:nil]; 这个视图控制器是我的UICollectionView的委托和数据源,所以我已经添加了UICollectionViewDataSource和UICollectionViewDelegate头。 我已经把一个UICollectionView放入笔尖,并添加了一个出口MyViewController: @property (strong, nonatomic) IBOutlet MyCollectionView *collectionViewController; 我已经在MyViewController的viewDidLoad中添加了这个: self.collectionViewController.dataSource = self; self.collectionViewController.delegate = self; 我还将以下内容添加到MyViewController中: – (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { NSLog(@"Items in section: %d", itemsArray.count); // returns correct […]

什么是禁用UICollectionView / UICollectionViewLayout旋转或界限更改的交叉淡化的最佳方法?

我有一个UICollectionViewLayout的子类放置单元格在一个圆圈。 对于调用shouldInvalidateLayoutForBoundsChange:布局返回YES 。 旋转时,初始位置的单元淡出,最后位置的单元淡入。 通过将下面的代码添加到我的布局中,我可以禁用淡入淡出,项目的圆圈似乎只是随着方向更改而旋转: – (UICollectionViewLayoutAttributes *)initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)itemIndexPath { return nil; } – (UICollectionViewLayoutAttributes *)finalLayoutAttributesForDisappearingItemAtIndexPath:(NSIndexPath *)itemIndexPath { return [self layoutAttributesForItemAtIndexPath:itemIndexPath]; } 为什么这些方法会被调用,因为文档似乎没有提示他们呢? 文档似乎声明他们被调用与从集合视图中插入和移除项目有关。 有没有更好的方法来禁用旋转过程中的交叉淡入淡出? 笔记: initialLayoutAttributesForAppearingItemAtIndexPath:文档指出,默认情况下,该方法返回nil但调用super返回的非零值。 我在UICollectionView方法deleteItemsAtIndexPaths: , moveItemAtIndexPath:toIndexPath:和insertItemsAtIndexPaths:上设置了符号断点,并且在旋转过程中都没有命中它们。

UICollectionReusableView – 缺less函数返回

考虑到UICollectionView的头部,我有一个奇怪的问题。 我基本上使用的代码: http : //www.raywenderlich.com/78551/beginning-ios-collection-views-swift-part-2 func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView { let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "dd.MM.yyyy' – 'HH:mm'" //1 switch kind { //2 case UICollectionElementKindSectionHeader: //3 let h = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "eventHeaderView", forIndexPath: indexPath) as eventHeader h.eventFirstline.text = "First Line" h.eventSecondline.text = thisEvent.eventName h.eventDate.text = dateFormatter.stringFromDate(thisEvent.startDate) h.eventDescription.text […]

Swift 3.0中的NSIndexPath和IndexPath

我最近把我的代码转换成了Swift 3.0。 我的集合视图和表视图数据源方法现在在它们的方法签名中包含IndexPath而不是NSIndexPath 。 但是在方法定义里面仍然是对NSIndexPathtypes转换IndexPath。 即 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell : NNAmenitiesOrFurnishingCollectionViewCell = self.amenitiesOrFurnishingCollectionView.dequeueReusableCell(withReuseIdentifier: "NNAmenitiesOrFurnishingCollectionViewCell", for: indexPath) as! NNAmenitiesOrFurnishingCollectionViewCell cell.facilityImageName = self.facilityArray[(indexPath as NSIndexPath).row].imageName cell.facilityLabelString = self.facilityArray[(indexPath as NSIndexPath).row].labelText return cell } 任何人都可以告诉我为什么indexPathtypes转换为NSIndexPath 。

如何设置UICollectionViewCell的位置?

所以据我所知,“协议方法”: (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 自动设置我创build的单元格的边界。 对于我的UICollectionViewCells ,这一切都很好,但我需要其中的一个在我指定的位置。 任何指针正确的方向将不胜感激。

iOS UICollectionView:具有交替网格alignment的圆形视图的单元格

我正在试图为UICollectionView的自定义单元格实现UICollectionView 。 现在默认情况下,圆形的排列方式与正常的方形单元相同:顶部圆和底部圆在同一条垂直线上。 我怎样才能改变这个alignment方式:上面的圆圈和下面的两个圆圈形成一个等边三angular形(顶部圆圈和底部圆圈的位置是按半径长度移动的)? 如下: from OOO OOO OOO to OOO OOO (no spacing among the circles) OOO

UICollectionViewCell中的UICollectionView(Swift)

我试图在每个可重用的UICollectionViewCell放置一个UICollectionViewCell 。 Ash Furrow方法对我来说工作不太好,因为使用一个UICollectionViewController类作为数据源,而两个UICollectionViews委托不起作用。 我最近的做法是将UICollectionViewController的视图放入每个单元格中,如本问题和本文档中所述 。 但是,当我去尝试加载视图,我的应用程序冻结。 在Xcodedebugging导航器中,CPU处于常量的107%,几秒钟后内存接近1GB。 在这个例子中,我试图在每个MainCollectionViewControllerCell获取一个ThumbnailCollectionViewController 。 每个ThumbnailCollectionViewControllerCell唯一一个尺寸为50×50的图像。 这是如何正确完成的? 在MainCollectionViewController中 override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! UICollectionViewCell let thumbsViewController = self.storyboard?.instantiateViewControllerWithIdentifier("ThumbnailColllection") as! ThumbnailCollectionViewController self.addChildViewController(thumbsViewController) thumbsViewController.view.frame = cell.bounds cell.addSubview(thumbsViewController.view) thumbsViewController.didMoveToParentViewController(self) } ThumbnailCollectionViewController let reuseIdentifier = "ThumbCell" let thumbnails = ["red", "green", "blue"] […]

UICollection View使用SDWebImage查看卷动滞后

背景 我search了SO和苹果论坛。 很多人谈到收集视图单元格与图像的performance。 他们中的大多数人表示,自从在主线程中加载图像以来,它在滚动上是滞后的。 通过使用SDWebImage ,图像应该加载在单独的线程中。 但是,在iPad模拟器中,仅在横向模式下才是滞后的。 问题描述 在纵向模式下,集合视图为每行加载3个单元格。 并没有滞后或微不足道的延迟。 在横向模式下,集合视图为每行加载4个单元格。 帧速率有明显的滞后和下降。 我用核心animation检查了仪器工具。 新单元出现时,帧速率降至8fps左右。 我不知道哪个行为给我带来如此低的performance收集视图。 希望有人知道这个技巧的一部分。 这里是相关的代码 在视图控制器中 – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { ProductCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"ProductViewCell" forIndexPath:indexPath]; Product *tmpProduct = (Product*)_ploader.loadedProduct[indexPath.row]; cell.product = tmpProduct; if (cellShouldAnimate) { cell.alpha = 0.0; [UIView animateWithDuration:0.2 delay:0 options:(UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction) animations:^{ cell.alpha = 1.0; } completion:nil]; } […]

ios UICollectionView检测滚动方向

我有一个collectionView。 我想检测滚动方向。 我有一个两个不同的animation风格,向下滚动和向上滚动。 所以我必须学习滚动方向。 CGPoint scrollVelocity = [self.collectionView.panGestureRecognizer velocityInView:self.collectionView.superview]; if (scrollVelocity.y > 0.0f) NSLog(@"scroll up"); else if(scrollVelocity.y < 0.0f) NSLog(@"scroll down"); 这只是在手指触摸工作。 不为我工作