【发布时间】:2014-03-14 19:03:09
【问题描述】:
我在管理带有 flowlayout 和方向的 UICollectionsView 时遇到问题。基本上,当我切换到横向时会出现问题,缺少一些 UICollectionViewCells。一旦我开始滚动,它们就会重新出现。它应该能够显示所有单元格,因为 contentSize 上有更多空间。
我什至尝试过我的布局:
- (BOOL) shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
{
return YES;
}
结果相同。
有人对这个问题有任何想法吗?我附上了一张关于我的布局如何组织和预期行为的图片:
要添加更多细节,每个颜色编码的单元格都属于它自己的部分,我将我的第二个部分向右移动方向更改使用:
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
NSArray* attributesToReturn = [super layoutAttributesForElementsInRect:rect];
for (UICollectionViewLayoutAttributes* attributes in attributesToReturn) {
NSIndexPath* indexPath = attributes.indexPath;
if (nil == attributes.representedElementKind) {
attributes.frame = [self layoutAttributesForItemAtIndexPath:indexPath].frame;
} else {
NSString *kind = attributes.representedElementKind;
attributes.frame = [self layoutAttributesForSupplementaryViewOfKind:kind atIndexPath:indexPath].frame;
}
}
return attributesToReturn;
}
layoutAttributesForElementsInRect 中的 item 数量在横向和纵向似乎完全不同。
【问题讨论】:
标签: ios ipad uicollectionview uicollectionviewcell uicollectionviewlayout