Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS UIScrollView animation after animation

Tags:

I want something similar in purpose to Flipboard slight flipping animation on app start. Flipboard when launched has this slight flipping of up and down to show users unfamiliar with the interface that it is flippable.

I have a UIScrollView I want to animate a bit to show the user that it's scrollable. So I want to scroll to the right a little bit and back. UIScrollView has a setContentOffset:animated: message without a completion clause. I find that calling it twice results in seemingly no animation. What if I want an animation after animation in succession?

EDIT: Thanks Levi for the answer. And for the record, there is UIViewAnimationOptionAutoreverse and UIViewAnimationOptionRepeat that I can use. So this is what I ended up with that works.

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]; }]; 
like image 235
huggie Avatar asked Jan 02 '13 09:01

huggie


2 Answers

For a scrollView, tableView or collectionView if you do something like this:

[self.collectionView setContentOffset:CGPointMake(self.collectionView.contentOffset.x+260.0,                                                   self.collectionView.contentOffset.y)                              animated:YES]; 

then you'll get back a:

-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView 

when the scroll finishes.

You do NOT get this callback if the user moves the view.

like image 99
Andrew Bennett Avatar answered Sep 21 '22 10:09

Andrew Bennett


Two options:

1) Use the -(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView delegate callback

2) Try to put it into an animation block (with ... animated:NO];), which has the completion part.

like image 21
Levi Avatar answered Sep 17 '22 10:09

Levi