實現很簡單:核心思想:建立三組相同cell,初始化的時候滑動到第1組的0,當滑動過程中超出第一組的範圍,立刻無動畫效果滑動到第一組對應的item上
核心代碼:利用scrollview的代理方法
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
//根據偏移量 計算出index 處於中間範圍不操作 其他情況滑動到第一組
int index = scrollView.contentOffset.x / [UIScreen mainScreen].bounds.size.width;
if(index >= 1*self.imagesArray.count && index < 2*self.imagesArray.count)
{
return;
}
int item = index % self.imagesArray.count;
NSIndexPath *indexpath = [NSIndexPath indexPathForItem:item inSection:1];
[self.collectionView scrollToItemAtIndexPath:indexpath atScrollPosition:0 animated:NO];
}