我的实现uiscrollview循环滚动的笨办法

本文介绍了一种在iOS应用中实现循环滚动视图的方法,通过重新排列数组元素并在UIScrollView上进行视图的添加和移除操作来模拟无限滚动效果,并保持了良好的视觉连续性。

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

其实不是真正意义上的循环滚动,只是判断当它快达到数组结尾时,把那个数组重新排序下,然后将原来加在UIScrollView上的remove,重新addsubview一次,有一点需要注意的是,为了不使其APP滚动过渡时闪一下,需要 exchangeObjectAtIndex 即重新排序数组



for (UIView *view in _myscrollView.subviews) {

                [view removeFromSuperview];

            }

            

            [self.applistArray exchangeObjectAtIndex:0 withObjectAtIndex:(self.applistArray.count-5)];

            [self.applistArray exchangeObjectAtIndex:1 withObjectAtIndex:(self.applistArray.count-4)];

            [self.applistArray exchangeObjectAtIndex:2 withObjectAtIndex:(self.applistArray.count-3)];

            [self.applistArray exchangeObjectAtIndex:3 withObjectAtIndex:(self.applistArray.count-2)];

            [self.applistArray exchangeObjectAtIndex:4 withObjectAtIndex:(self.applistArray.count-1)];

            

            

            for (int i = 0; i < self.applistArray.count; i++) {

                AppInformationCell *appInformationCell = [[AppInformationCell alloc] init];

                appInformationCell.frame = CGRectMake(i * 80, 0, 80, 80);

                [appInformationCell refreshWithData:[self.applistArray objectAtIndex:i]];

                

                appInformationCell.tag = i+1;

                

                [_myscrollView addSubview:appInformationCell];

                

                if (appInformationCell.tag == 1) {

                    appInformationCell.transform=CGAffineTransformMakeScale(0.7f, 0.7f);

                } else if (appInformationCell.tag == 2) {

                    appInformationCell.transform=CGAffineTransformMakeScale(0.8f, 0.8f);

                } else if (appInformationCell.tag == 3) {

                    appInformationCell.transform=CGAffineTransformMakeScale(1.0f, 1.0f);

                } else if (appInformationCell.tag == 4) {

                    appInformationCell.transform=CGAffineTransformMakeScale(0.8f, 0.8f);

                } else if (appInformationCell.tag == 5) {

                    appInformationCell.transform=CGAffineTransformMakeScale(0.7f, 0.7f);

                } else {

                    appInformationCell.transform=CGAffineTransformMakeScale(0.67f, 0.67f);

                }

            }

            

            _myscrollView.contentOffset = CGPointMake(40, 0);

            linshiInt = 0;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值