我有一个UICollectionViewController
使用UICollectionViewFlowLayout
我itemSize
的大小的地方UICollectionView
.基本上,这是单元格的线条布局,其中每个单元格是全屏的并且水平滚动.
在我的UICollectionViewFlowLayout
子类中,我已覆盖prepareLayout
如下:
- (void)prepareLayout {
self.itemSize = self.collectionView.frame.size;
self.scrollDirection = UICollectionViewScrollDirectionHorizontal;
self.collectionView.pagingEnabled = YES;
self.minimumLineSpacing = 0.0;
self.minimumInteritemSpacing = 0.0;
self.sectionInset = UIEdgeInsetsZero;
self.footerReferenceSize = CGSizeZero;
self.headerReferenceSize = CGSizeZero;
}
Run Code Online (Sandbox Code Playgroud)
这UICollectionViewController
是非常基本的一个部分返回10项.我在GitHub中包含了一个示例项目以获取更多详细信息.
一切似乎都正确设置.它在模拟器和设备上看起来正确但是,当显示集合视图时,控制台上会记录一个错误:
Run Code Online (Sandbox Code Playgroud)the behavior of the UICollectionViewFlowLayout is not defined because: the item height must be less that the height of the UICollectionView minus the section insets top and bottom values.
另请注意,我的示例中的集合视图控制器位于导航控制器中,虽然在示例中看起来并不是特别必要,但在我的实际案例中,我需要导航控制器中的集合视图.