Created
July 13, 2017 07:16
-
-
Save juwencheng/05759e237b58008384c61adc3e9a8562 to your computer and use it in GitHub Desktop.
UICollectionView 分页滚动
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
// original : https://stackoverflow.com/questions/24303883/uicollectionview-with-paging-enable | |
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView | |
withVelocity:(CGPoint)velocity | |
targetContentOffset:(inout CGPoint *)targetContentOffset | |
{ | |
CGFloat cellWidth = self.cellWidth; | |
CGFloat cellPadding = 9; | |
NSInteger page = (scrollView.contentOffset.x - cellWidth / 2) / (cellWidth + cellPadding) + 1; | |
if (velocity.x > 0) page++; | |
if (velocity.x < 0) page--; | |
page = MAX(page,0); | |
CGFloat newOffset = page * (cellWidth + cellPadding); | |
targetContentOffset->x = newOffset; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment