Skip to content

Instantly share code, notes, and snippets.

@ajayjapan
Created August 28, 2014 18:16
Show Gist options
  • Save ajayjapan/5e7ba49e51f1ca24b76d to your computer and use it in GitHub Desktop.
Save ajayjapan/5e7ba49e51f1ca24b76d to your computer and use it in GitHub Desktop.
Adjust content size of collection view when flexible iOS 8 simulator size changes
@interface UICollectionViewFlowLayout (InvalidateOnBoundsChange)
@end
@implementation UICollectionViewFlowLayout (InvalidateOnBoundsChange)
- (UICollectionViewLayoutInvalidationContext *)invalidationContextForBoundsChange:(CGRect)newBounds {
UICollectionViewLayoutInvalidationContext *context = [super invalidationContextForBoundsChange:newBounds];
CGRect oldBounds = self.collectionView.bounds;
CGFloat widthAdjustment = newBounds.size.width - oldBounds.size.width;
CGFloat heightAdjustment = newBounds.size.height - oldBounds.size.height;
context.contentSizeAdjustment = CGSizeMake(widthAdjustment, heightAdjustment);
return context;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment