Created
September 4, 2014 09:43
-
-
Save pionl/432fc8059dee3b540e38 to your computer and use it in GitHub Desktop.
First cell starts in center of the view.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (CGSize)collectionViewContentSize { | |
CGSize contentSize = [super collectionViewContentSize]; | |
// we need to center last view | |
int items = [[self collectionView] numberOfItemsInSection:0]; | |
UICollectionViewLayoutAttributes* layoutAttribute = (UICollectionViewLayoutAttributes*)[super layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForItem:items-1 inSection:0]]; | |
float startX = contentSize.width - self.collectionView.bounds.size.width + self.collectionView.bounds.size.width / 2; | |
startX = layoutAttribute.frame.origin.x - startX; | |
startX += layoutAttribute.size.width / 2; | |
contentSize.width += startX; | |
layoutAttribute = (UICollectionViewLayoutAttributes*)[super layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]; | |
[[self collectionView] setContentInset:UIEdgeInsetsMake(0, self.collectionView.bounds.size.width / 2 - layoutAttribute.frame.size.width / 2, 0, 0)]; | |
return contentSize; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works for me (for a known size):