Reputation: 427
Objective
The scroll animation keep looping and keep go on the "AfterDone" method even the animation not yet complete.
- (void) afterAnimationStops{
float newOffSetX = _tableview.bounds.size.width-wContentBgImg;
NSLog(@"Inside AutoMove > %d",LzAutoMove);
if(leftright==1 && LzAutoMove==0)
{
NSLog(@"Come In > 1");
LzAutoMove = 1;
leftright = 2;
[UIScrollView animateWithDuration:3.0f
delay:0.0f
options:UIViewAnimationOptionCurveEaseOut
animations:^{
[UIScrollView beginAnimations:@"scrollAnimation" context:nil];
[UIScrollView setAnimationDuration:3.0f];
LzcurrentLocation = (-newOffSetX);
[imgCell.scrollview setContentOffset:CGPointMake((-newOffSetX), 0)];
[UIScrollView commitAnimations];
}
completion:^(BOOL finished){
if (finished) {
[self afterDone];
}
}];
}else{
if(LzAutoMove==0){
NSLog(@"Come In > 2");
LzAutoMove = 1;
leftright = 1;
[UIScrollView animateWithDuration:3.0f
delay:0.0f
options:UIViewAnimationOptionCurveEaseOut
animations:^{
[UIScrollView beginAnimations:@"scrollAnimation" context:nil];
[UIScrollView setAnimationDuration:3.0f];
LzcurrentLocation = 0;
[imgCell.scrollview setContentOffset:CGPointMake(0, 0)];
[UIScrollView commitAnimations];
//[UIScrollView setAnimationDidStopSelector:@selector(afterDone)];
}
completion:^(BOOL finished){
if (finished) {
[self afterDone];
}
}];
}
}
}
- (void) afterDone{
NSLog(@"Done");
LzAutoMove = 0;
[self afterAnimationStops];
}
i still learning how to use the "animation completed" method, is that any one can show me where i doing wrong? thanks!
Upvotes: 0
Views: 833
Reputation: 103
You can use UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
flags for your animation option, the animation will auto repeat and reverse to original state after each completion.
[UIView animateWithDuration:3.0f
delay:0.0f
options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
animations:^{
[imgCell.scrollview setContentOffset:contentOffset];
}
completion:^(BOOL finished){
}];
Upvotes: 2