【发布时间】:2016-06-05 12:16:01
【问题描述】:
我面临一个奇怪的情况,如果 UICollectionView 第一次加载 0 个单元格,它会改变大小。如果第一次加载超过 0 个单元格,它会保持正确的大小。这种行为对我来说没有任何意义,我不知道如何纠正它。
我正在使用分页集合视图,类似于here 中描述的内容。
这意味着我将单元格大小设置为与集合视图的大小相同:
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return collectionView.bounds.size;
}
奇怪的是我收到了这个错误信息:
2016-02-23 14:27:10.574 the behavior of the UICollectionViewFlowLayout is not defined because:
2016-02-23 14:27:10.574 the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
2016-02-23 14:27:10.575 The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x7fa90ac86d30>, and it is attached to <UICollectionView: 0x7fa90c84da00; frame = (0 0; 414 150); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7fa90ac88450>; layer = <CALayer: 0x7fa90ac85b70>; contentOffset: {0, 0}; contentSize: {828, 187}> collection view layout: <UICollectionViewFlowLayout: 0x7fa90ac86d30>.
2016-02-23 14:27:10.575 Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
基本上告诉我单元格的高度大于集合视图的高度,这实际上没有任何意义,因为我将单元格的大小设置为与集合视图相同。
在我看来,collection view 的高度取决于它是否为空,这对我来说没有任何意义。有谁知道我该如何解决这个问题或对如何解决这个问题有任何建议?
更新:
当我问这个问题时,我似乎没有完全理解这个问题。我认为问题是由于我第一次加载集合视图时没有任何单元格。所以我认为一个简单的解决方案是在加载内容时放置一个空的占位符单元格。不幸的是,当我重新加载数据时,单元格的大小仍然被搞砸了。所以问题似乎是大小只有在我第一次加载集合视图时才正确,而在任何后续重新加载时,大小都会变得不正确。
【问题讨论】:
-
uicollectionview 的 contentinset 怎么样?
标签: ios autolayout uicollectionview uistoryboard nib