动画后的iOS UIScrollView动画

hug*_*gie 18 animation uiscrollview ios

我想要一些类似于Flipboard的东西,在应用程序启动时轻微翻动动画.启动时Flipboard上下轻微翻转,以显示用户不熟悉它可翻转的界面.

我有一个UIScrollView我想动画一下,向用户显示它是可滚动的.所以我想向后滚动一点点.UIScrollView有一条setContentOffset:animated:没有完成子句的消息.我发现调用它两次导致看似没有动画.如果我想在动画之后连续播放动画怎么办?

编辑:谢谢Levi的答案.并记录在案,有UIViewAnimationOptionAutoreverseUIViewAnimationOptionRepeat我可以使用.所以这就是我最终得到的结果.

CGPoint offset = self.scrollView.contentOffset;
CGPoint newOffset = CGPointMake(offset.x+100, offset.y);

[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAutoreverse |UIViewAnimationOptionRepeat animations:^{
    [UIView setAnimationRepeatCount: 2];
    [self.scrollView setContentOffset:newOffset animated: NO];
} completion:^(BOOL finished) {
    [self.scrollView setContentOffset:offset animated:NO];
}];
Run Code Online (Sandbox Code Playgroud)

And*_*ett 39

对于scrollView,tableView或collectionView,如果你这样做:

[self.collectionView setContentOffset:CGPointMake(self.collectionView.contentOffset.x+260.0,
                                                  self.collectionView.contentOffset.y)
                             animated:YES];
Run Code Online (Sandbox Code Playgroud)

然后你会回来:

-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
Run Code Online (Sandbox Code Playgroud)

滚动完成时

如果用户移动视图,则不会收到此回调.

  • 此外,如果没有动画(例如滚动偏移为0),则不会调用scrollViewDidEndScrollingAnimation. (7认同)
  • 只有当所有setContentOffset调用都应该导致相同的函数时,这个(好的)答案才有效.例如,如果仅对某些setContentOffset调用需要"完成",则需要一些代码杂技才能实现此目的. (2认同)

Lev*_*evi 27

两种选择:

1)使用-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView委托回调

2)尝试将其放入动画块(带... animated:NO];),其中包含完成部分.