横向取消UICollectionViewCells

我有一个问题,用stream布局和方向来pipe理我的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中的项目数量在横向和纵向上完全不同。

最后搞清楚了。 当它在风景上的时候,我把这个矩形增加到了一个很大的尺寸:

 - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { CGRect *newRect = CGRectMake(0,0, screensize.width, screensize.height); NSArray* attributesToReturn = [super layoutAttributesForElementsInRect:newRect]; ... }