zoukankan      html  css  js  c++  java
  • 图片无限轮播-最简单的实现方法

    collectionView中仅仅有三个cell 每次显示的都是第二个cell


    - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

        

        CycleViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];

        //indexPath.item - 1 相当于index左移加右移减一

       //indexPath.item - 1 假设左移就相当于要显示第三个cell 2-1  ,相当于self.currentIndex + 1

       //indexPath.item - 1 假设右移就相当于要显示第一个cell 0-1  。相当于self.currentIndex - 1

        NSInteger index = (self.currentIndex + indexPath.item - 1 + self.imageURLs.count) % self.imageURLs.count;

        

        cell.imageURL = self.imageURLs[index];

        

        return cell;

    }


    // 在滚动视图全然停止滚动后会调用的方法

    - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {

        

        // 1. 依据contentOffset能够推断出停留住的页面

        int page = scrollView.contentOffset.x / scrollView.bounds.size.width;

        NSLog(@" %d ", page);

        

        // 2. 假设是第0页,self.currentIndex - 1,假设是第2,self.currentIndex +1;

        self.currentIndex = (self.currentIndex + page - 1 + self.imageURLs.count) % self.imageURLs.count;

        

        // 3. collection滚动会第一个页面

        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:1 inSection:0];

        [self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];

    }

  • 相关阅读:
    sql server 跨库操作
    FPGA使用技巧
    MATLAB学习(3)
    FPGA统计摄像头输出-基于MD9T112
    zedboard VmodCAM 图像采集 HDMI输出显示
    VmodCAM图像采集 VGA显示
    EDK中如何使用ISE中生成的IP
    如何将HDL文件实例化到XPS中
    ubuntu下安装 Source insight
    VmodCAM 初始化
  • 原文地址:https://www.cnblogs.com/cxchanpin/p/7398899.html
Copyright © 2011-2022 走看看