collectionview實現無限輪播

實現很簡單:核心思想:建立三組相同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];
   
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章