水平滚动的UICollectionView,并且每个整个屏幕总是有2个单元并排。我需要滚动停止在一个单元格的开始。启用分页功能后,集合视图会一次滚动整个页面,即2个单元格,然后停止。 我需要启用单个单元格的滚动,或者停止在单元格边缘的多个单元格滚动。
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset { UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout*)collectionView.collectionViewLayout; CGFloat pageWidth = layout.itemSize.width + layout.minimumLineSpacing; int minSpace = 10; int cellToSwipe = (scrollView.contentOffset.x)/(pageWidth + minSpace) + 0.5; if (cellToSwipe < 0) { cellToSwipe = 0; } else if (cellToSwipe >= self.articles.count) { cellToSwipe = self.articles.count - 1; } [self.articlesCollectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:cellToSwipe inSection:0] atScrollPosition:UICollectionViewScrollPositionLeft animated:YES]; }
转载请注明来源: UICollectionView按单元格分页而不是屏幕 - 朱凯博客
支付宝
微信