I have a UIViewController containing a UICollectionView using a UICollectionViewFlowLayout.
The view controller is the detail view controller of a UISplitViewController.
The view controller is the flow layout's delegate and the sizes of the UICollectionViewCells are calculated according to the available space in the collection view. (for instance itemSize = width/3,height/2)
In iOS8 Apple introduced the API to collapse the master section of the split view controller.
I want to invalidate my collection view's layout when the collection view expands in order to force recalculation of the item sizes.
I thought of adding the appropriate code in the new size methods introduced in iOS8 - but none of them are called when collapsing the master's side.
Here is the code I've tried. It isn't called:
-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
[self.collectionView.collectionViewLayout invalidateLayout];
[self.collectionView reloadData];
}];
}
-(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
[self.collectionView.collectionViewLayout invalidateLayout];
[self.collectionView reloadData];
}