gpt4 book ai didi

ios - 在 UICollectionView 中创建慢速滚动到 indexPath

转载 作者:IT王子 更新时间:2023-10-29 08:08:19 26 4
gpt4 key购买 nike

我正在开展一个项目,我在其中使用 UICollectionView 创建一个“图像自动收报机”,我在其中为一系列 Logo 做广告。 collectionView 高 1 项,长 12 项,一次显示两到三个项目(取决于可见 Logo 的大小)。

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

有没有人能做到这一点?我可以让滚动工作使用

[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 - 在 UICollectionView 中创建慢速滚动到 indexPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13006972/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com