ios – 在UICollectionView中创建缓慢滚动到indexPath

我正在使用一个项目,我正在使用UICollectionView来创建一个“图像报告器”,我在那里广告一系列标志. collectionView是一个项目高和十二个项目长,一次显示两到三个项目(取决于徽标的大小可见).

我想从第一个项目到最后一个缓慢的自动滚动动画,然后重复.

有没有人能够做这项工作?我可以使滚动工作

[myCollection scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:(myImages.count -1) inSection:0] atScrollPosition:UICollectionViewScrollPositionRight animated:YES];

但这太过分了!

[UIView animateWithDuration:10 delay:2 options:(UIViewAnimationoptionAutoreverse + UIViewAnimationoptionRepeat) animations:^{
    [myCollection scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:(myImages.count -1) inSection:0] atScrollPosition:UICollectionViewScrollPositionRight animated:NO];
} completion:nil];

这产生了所需的滚动速度,但是只有最后几个单元格在系列中可见.我怀疑他们(甚至起始的可见细胞)正在出场.

有什么想法吗?

解决方法

你可以尝试这种方法
@property (nonatomic,assign) CGPoint scrollingPoint,endPoint;
@property (nonatomic,strong) NSTimer *scrollingTimer;
@synthesize scrollingPoint,endPoint;
@synthesize scrollingTimer;

- (void)scrollSlowly {
    // Set the point where the scrolling stops.
    self.endPoint = CGPointMake(0,300);
    // Assuming that you are starting at {0,0} and scrolling along the x-axis.
    self.scrollingPoint = CGPointMake(0,0);
    // Change the timer interval for speed regulation. 
    self.scrollingTimer = [NSTimer scheduledTimerWithTimeInterval:0.015 target:self selector:@selector(scrollSlowlyToPoint) userInfo:nil repeats:YES];
}

- (void)scrollSlowlyToPoint {
    self.collectionView.contentOffset = self.scrollingPoint;
    // Here you have to respond to user interactions or else the scrolling will not stop until it reaches the endPoint.
    if (CGPointEqualToPoint(self.scrollingPoint,self.endPoint)) {
        [self.scrollingTimer invalidate];
    }
    // Going one pixel to the right.
    self.scrollingPoint = CGPointMake(self.scrollingPoint.x,self.scrollingPoint.y+1);
}

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...