This is the view of the app when it is in portrait mode.
When it is rotated to landscape mode it looks like this
The view debugger shows that the UIWindow
is not rotating as shown here
The UICollectionViewController
is created via StoryBoard. I've tried subclassing UICollectionViewFlowLayout
that implements shouldInvalidateLayoutForBoundsChange
, but it does not fix my issue.
- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds {
CGRect oldBounds = self.collectionView.bounds;
if (CGRectGetWidth(newBounds) != CGRectGetWidth(oldBounds)) {
return YES;
}
return NO;
}
Please provide ideas of what to check next or requests for additional code to debug.
Edit - As suggested by MirekE, I attempted to add constraints to the CollectionView
but was unable. All of the options for Editor->Pin are unavailable for the CollectionView
.
Edit, response to Andrea -
I'm targeting iOS8.3. My understanding is that the main method called at rotation is viewWillTransitionToSize:withTransitionCoordinator:
, which is from the UIContentContainer
protocol. I've added the following to my CollectionViewController, but same problem persists
-(void)viewWillTransitionToSize:(CGSize)size
withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator {
[self.collectionView.collectionViewLayout invalidateLayout];
[self.collectionView reloadData];
}
The problem was that the
collectionView
outlet was not properly set. After setting thecollectionView
, all works properly.collectionView
outlet not set:collectionView
outlet set: