I have a problem with the size of the collectionView element. I want to display 3 elements per line for portrait mode and 6 for landscape. I configured -layoutSubviews as follows:
- (void)layoutSubviews { [super layoutSubviews]; if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait || ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortraitUpsideDown)) { //Portrait orientation self.flowLayoutPortrait.itemSize = CGSizeMake(106, 106); } else if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight)) { //Landscape orientation self.flowLayoutPortrait.itemSize = CGSizeMake(93, 93); } [self.collectionView.collectionViewLayout invalidateLayout]; }
But the cell size is not updated, it always remains unchanged for both orientations. If I create 2 flowLayouts and use:
[self.collectionView setCollectionViewLayout:self.flowLayoutLandscape]
Everything works, but I really don't like how they change. The animation is really bad. And since itemSize is the only property that needs to be updated, using 1 layout seems like the best option.
How do I tell CollectionView to update the layout?
source share