iOS scrollView循环自动滚动

本文探讨了图像处理和AR特效技术的集成应用,详细介绍了OpenGL ES滤镜、OpenCV图像处理等关键技术,以及如何在实时场景中实现美颜直播特效、视频剪辑和3D空间视频等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

额外创建两个imageView

把最后一张图片添加到最前面

把第一张图片添加到最后面

-(void)setData:(FunData *)data

{

    _data = data;

    

    NSMutableArray *imageArray = [NSMutableArray array];

    [imageArray addObject:[data.imageArray lastObject]];

    [imageArray addObjectsFromArray:data.imageArray];

    [imageArray addObject:[data.imageArray firstObject]];


    float x = 0;

    

    for (NSString *urlString in imageArray)

    {

        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(x, 0, self.contentView.width, self.contentView.height)];

        NSLog(@"%@",urlString);

        [imageView sd_setImageWithURL:[NSURL URLWithString:urlString]];

        [self.scrollView addSubview:imageView];

        

        x += self.contentView.width;

    }

    

    self.pageControl.numberOfPages = data.imageArray.count;

    self.pageControl.currentPage = 0;

    

    self.scrollView.delegate = self;

    self.scrollView.contentSize = CGSizeMake(x, self.contentView.height);

    self.scrollView.contentOffset = CGPointMake(self.contentView.width, 0);

    self.scrollView.pagingEnabled = YES;

    self.scrollView.showsHorizontalScrollIndicator = NO;

    

    [self startScroll];

}


#pragma mark - 自动滚动

-(void)autoScroll

{

    NSInteger currentPage = self.pageControl.currentPage >=self.data.imageArray.count-1? 0:self.pageControl.currentPage+1;

    self.pageControl.currentPage = currentPage;

    CGFloat pointX = self.scrollView.width * (currentPage + 1);

    self.scrollView.contentOffset = CGPointMake(pointX, 0);

}


-(void)startScroll

{

    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(autoScroll) userInfo:nil repeats:YES];

    [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

    _timer = timer;

}


-(void)stopScroll

{

    [self.timer invalidate];

    self.timer = nil;

}


-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

{

    NSInteger page = scrollView.contentOffset.x / scrollView.width - 1;

    self.pageControl.currentPage  = page;

    

    if (page == self.data.imageArray.count)

    {

        self.pageControl.currentPage = 0;

        [self.scrollView setContentOffset:CGPointMake(self.contentView.width, 0) animated:NO];

    }

    else if (page == -1)

    {

        self.pageControl.currentPage = self.data.imageArray.count;

        [self.scrollView setContentOffset:CGPointMake(self.contentView.width * self.data.imageArray.count, 0) animated:NO];

    }

}


-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView

{

    [self stopScroll];

}


-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate

{

    [self startScroll];

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值