我需要在动画重复之前调用某个方法.我不知道在哪里放置那行代码.
这是我为对象设置动画的代码:
[UIView animateWithDuration:speed delay:delay options:UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionCurveLinear|UIViewAnimationOptionRepeat animations:^(void){ cloud.frame = (CGRectMake(cloud.frame.origin.x, cloud.frame.origin.y+600, cloud.frame.size.width, cloud.frame.size.height)); }completion:^(BOOL finished){ if (finished){ [cloud setBackgroundImage:[UIImage imageNamed:@"cloudWhite.png"] forState:UIControlStateNormal]; } }];
完成部分中调用的方法不会在每次重复之前执行,而是仅在整个动画完成之后执行,并且在重复之后 - 在这种情况下 - 从不执行.
我的问题是,如何在每个动画重复之前调用一个方法?
我建议重构你的动画,这样它就不会用了UIViewAnimationOptionRepeat
.相反,编写一个执行动画的单个循环的方法.然后添加一个以递归方式调用该方法的完成方法块.
您还可以在完成块中的动画的每次迭代中放置要触发的方法调用.