我有一个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;
}
UICollectionViewController
是非常基本的,在一个部分返回10个项目.为了了解更多细节,我加入了sample project on GitHub.
一切似乎都设置正确.它在模拟器和设备上看起来是正确的,但当显示采集视图时,控制台上会记录一个错误:
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.
Note also that the collection view controller in my example is in a navigation controller and while that doesn't look particularly necessary in the example, in my real-world case I need the collection view in a navigation controller.