Skip to content

Instantly share code, notes, and snippets.

@AlexandrFadeev
Last active June 27, 2019 13:55
Show Gist options
  • Save AlexandrFadeev/4033add8e354d9dbe23f72415ebcdc7a to your computer and use it in GitHub Desktop.
Save AlexandrFadeev/4033add8e354d9dbe23f72415ebcdc7a to your computer and use it in GitHub Desktop.
CollectionView layout on device rotation
// Subclass UICollectionViewFlowLayout and overrite this method.
- (UICollectionViewLayoutInvalidationContext *)invalidationContextForBoundsChange:(CGRect)newBounds {
UICollectionViewFlowLayoutInvalidationContext *context = (UICollectionViewFlowLayoutInvalidationContext *)[super invalidationContextForBoundsChange:newBounds];
context.invalidateFlowLayoutDelegateMetrics = (
CGRectGetWidth(newBounds) != CGRectGetWidth(self.collectionView.bounds) ||
CGRectGetHeight(newBounds) != CGRectGetHeight(self.collectionView.bounds)
);
return context;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment