Skip to content

Instantly share code, notes, and snippets.

@nenadvulic
Created March 3, 2016 10:56
Show Gist options
  • Save nenadvulic/f978ec0f71bfc83c9918 to your computer and use it in GitHub Desktop.
Save nenadvulic/f978ec0f71bfc83c9918 to your computer and use it in GitHub Desktop.
UICollectionView snap cell vertically
- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity {
CGPoint contentOffset = CGPointZero;
NSInteger itemHeight = 130;
NSInteger padding = 10;
NSInteger index = round(proposedContentOffset.y / (itemHeight + padding));
NSInteger x = (itemHeight + padding) * index;
contentOffset = CGPointMake(proposedContentOffset.x, x);
return contentOffset;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment