目标
滚动动画保持循环并继续保持" AfterDone"方法甚至动画尚未完成。
- (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];
}
我还在学习如何使用"动画完成"方法,是任何人都可以告诉我我做错了什么?谢谢!
答案 0 :(得分:2)
您可以使用UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
标记作为动画选项,动画将在每次完成后自动重复并反转为原始状态。
[UIView animateWithDuration:3.0f
delay:0.0f
options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
animations:^{
[imgCell.scrollview setContentOffset:contentOffset];
}
completion:^(BOOL finished){
}];