没有定义UICollectionViewFlowLayout的行为,因为单元格宽度大于collectionView宽度

2015-08-18 16:07:51.523 Example[16070:269647] the behavior of the
UICollectionViewFlowLayout is not defined because: 2015-08-18
16:07:51.523
Example[16070:269647] the item width must be less than
the width of the UICollectionView minus the section insets left and
right values,minus the content insets left and right values.
2015-08-18 16:07:51.524 Example[16070:269647] The relevant
UICollectionViewFlowLayout instance is,and it is attached to ; animations = {
position=;
bounds.origin=;
bounds.size=; }; layer = ; contentOffset: {0,0}; contentSize: {1024,770}>
collection view layout: .
2015-08-18 16:07:51.524 Example[16070:269647] Make a symbolic
breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch
this in the debugger.

这是我得到的,我做的是什么

func collectionView(collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
        return CGSizeMake(self.collectionView!.frame.size.width - 20,66)
    }

当我从风景旋转到纵向时,控制台仅在iOS 9中显示此错误消息,有没有人知道这是怎么回事,如果有这样的修复?

解决方法

它的发生是因为您的集合视图单元格的宽度大于旋转后的集合视图宽度.假设您具有1024×768屏幕,并且集合视图填充屏幕.当设备为横向时,单元格的宽度将为self.collectionView.frame.size .width – 20 = 1004,它大于纵向的集合视图宽度= 768.调试器说“项宽必须小于UICollectionView的宽度减去插入左和右值的部分,减去左边的内容插入和正确的价值观“.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...