动画后的iOS UIScrollView动画

时间:2013-01-02 09:27:51

标签: ios animation uiscrollview

我想要一些类似于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];
}];

2 个答案:

答案 0 :(得分:37)

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

[self.collectionView setContentOffset:CGPointMake(self.collectionView.contentOffset.x+260.0,
                                                  self.collectionView.contentOffset.y)
                             animated:YES];
然后你会得到一个:

-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
滚动完成时

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

答案 1 :(得分:24)

两个选项:

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

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