没有定义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的宽度减去插入左和右值的部分,减去左边的内容插入和正确的价值观“.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...