【发布时间】:2012-10-11 23:59:25
【问题描述】:
我正在做一个项目,我正在使用 UICollectionView 创建一个“图像代码”,我在其中宣传一系列徽标。 collectionView 高 1 项,长 12 项,一次显示 2 到 3 项(取决于可见徽标的大小)。
我想做一个缓慢的自动滚动动画,从第一项到最后一项,然后重复。
有没有人能够完成这项工作?我可以让滚动工作使用
[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];
这会产生所需的滚动速度,但在系列中只有最后几个单元格可见。我怀疑它们(甚至是起始可见单元格)正在立即出队。
有什么想法吗?
【问题讨论】:
-
我尝试了您的代码,实际上是 scrollToItemAtIndexPath 将您带到您传递的特定 indexPath 即 [myImages.count -1] ,因此该 indexPath 处的图像可见
标签: ios scroll uiviewanimation nsindexpath uicollectionview