UICollectionViewFlowLayout Size Warning When Rotating Device to Landscape
I was getting the same warning. Unsatisfied with the "reloadData" approach, I found that calling [self.collectionView.collectionViewFlowLayout invalidateLayout]
before setting the frame of the collection view silenced the warning and yielded the expected results.
Not to throw another shrimp on this loaded, yet unaccepted, barbie.
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { [collectionView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)]; return CGSizeMake(100, collectionView.frame.size.height);}
Setting the content insets just before returning the cell size did the trick for me.
Note:
I am using a container view in a storyboard to load the collection view within a UIViewController. I tried setting this on the flowLayout object in the storyboard. The collection view in the storyboard. And overriding one of the UICollectionViewDelegateFlowLayout; though I do not remember which one. I'm also not sure if this will work for a vertical layout.
In
[UIViewController willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration]
I called the, [UICollectionViewLayout invalidateLayout]
and seems to work good.