当单元格仍然显示时,UICollectionView中的大单元格被移除

我有一个UICollectionView包含一些大的UICollectionViewCells。 这些单元格非常大,它们完全填充了UICollectionView边界并在屏幕之外延伸。 问题是从UICollectionView中删除大单元,并在仍然显示的时候排队等待重用,导致空白视图。 如果我继续在空白UICollectionView区域上滚动,最终单元格的最后部分出现,下一个单元格的开始就出现在正确的位置。 我已经有效地禁用了单元格重用,问题仍然存在,显然是因为UICollectionView认为单元格不再显示,因为没有angular落在集合视图的边界内。 为了演示一个集合视图是一个单栏,并有一个10000px高的单元格,滚动非常高的单元格时,它将在大约1000px的内容滚动离开屏幕后消失,并将重新出现以显示最终的1000px内容为细胞。 你可以下载一个简单的原型应用程序来显示这个问题: http : //jack.cox.s3.amazonaws.com/collectionviewprototype.zip

这个问题在debugging日志中伴随着这个警告发生了:

UICollectionViewFlowLayout的行为没有定义,因为:项目的高度必须小于UICollectionView的高度减去顶部和底部的值。

看来,开箱UICollectionViewFlowLayout不支持大于屏幕的单元格。

这个问题正在被追踪为雷达#12889164

如果你仍然在寻找一个快速解决scheme,试试这个修补程序:当一个单元格被检测到有一个比collectionview更高的高度时,集合视图只需要比单元格更大。 所以设置collecitonView框架要更大一些,正确的内容和指标插入。

- (void)updateCollectionViewForLargeCellHeight:(CGFloat)largeCellHeight { CGFloat currentCollectionViewHeight = CGRectGetHeight(self.collectionView.frame); if (largeCellHeight > currentCollectionViewHeight) { self.collectionViewBottomConstraint = -largeCellHeight; //This is the bottom constraint of the collectionView to its superview. //If you are not using constraints, simply set the frame for the collectionView UIEdgeInsets edgeInset = UIEdgeInsetsMake(0, 0, largeCellHeight, 0); self.collectionView.contentInset = edgeInset; self.collectionView.scrollIndicatorInsets = edgeInset; [self.collectionView needsUpdateConstraints]; } } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { CGSize size; [self updateCollectionViewForLargeCellHeight:size.height]; return size; } 

我已经使用UICollectionView与屏幕大小的单元格。 对于iPad的单元格大小是768×1024。 并没有发现任何问题。 请确保您已设置Min Spacing For CellsMin Spacing For CellsFor Lines0也返回正确的CGSizeUIEdgeInsets如下


 - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { CGSize retval; retval.width=maxWidth; //768 in case of iPad retval.height=maxHeight; //1024 in case of iPad return retval; } 

 - (UIEdgeInsets)collectionView: (UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { return UIEdgeInsetsMake(0 , 0, 0, 0); }