【发布时间】:2016-04-12 06:35:45
【问题描述】:
我有一个集合视图,其中我有 10 个从 web 服务加载的图像。我想将该图像视图从第一个位置自动滚动到最后一个位置,然后在该页面出现时连续滚动到第一个位置。 我使用下面的方法
-(void)scrollSlowly
{
CATransition *transition = [CATransition animation];
transition.duration = 4.0f;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[UIView animateWithDuration:5.0f
delay:3.0f
options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
animations:^{
[self.CollectionView setContentOffset:CGPointMake(CGFLOAT_MAX ,0)];
}
completion:nil];
[self.CollectionView.layer addAnimation:transition forKey:@"transition"];
}
-(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+1, self.scrollingPoint.y);
}
我想在 Objective-C 中水平自动滚动。提前致谢
【问题讨论】:
-
你为什么不用
- (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated? -
是的,我也使用它,但它不会让我重复缓慢滚动...@sourcer
标签: ios objective-c uiscrollview uicollectionview