UICollectionViewCells disappears in landscape orientation

I have a problem managing my UICollectionsView with flowlayout and orientation. Mostly problems arise when I switch to landscape, some of the UICollectionViewCells are missing. They appear again when I start to scroll. It should be able to show the whole cell, since there is much more space on contentSize.

I even tried in my layout:

- (BOOL) shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds { return YES; } 

With the same results.

Anyone have any ideas on this issue? I included an image about how my layout is organized and the expected behavior:

enter image description here

To add more detailed information, each of the color-coded cells belongs to its own section, and I change my second part to the right to change the orientation using:

 - (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; } 

It seems that the number of elements in layoutAttributesForElementsInRect is completely different from the landscape and in the portrait.

0
ios ipad uicollectionview uicollectionviewcell uicollectionviewlayout
source share
1 answer

Finally, find out. I enlarged my rectangle to a large size when it is in the landscape:

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

All Articles