【发布时间】:2015-07-08 06:23:31
【问题描述】:
我有一个 iOS 应用程序,它运行几个不同的 UIViewAnimation 块来为屏幕上的几个不同对象设置动画。这一切都有效,但我怎样才能停止其中一个动画块而不停止其余部分?
我尝试过使用以下方法:
[button.layer removeAllAnimations];
但它什么也没做,动画只是继续。
然后,我尝试使用一个简单的 BOOL 值,并在 BOOL 设置为“NO”后从该方法将动画设置为 return,但这也不起作用。
这是我要停止的动画:
-(void)undo_animation:(int)num {
// Fade out/in the number button label
// animation which lets the user know
// they can undo this particular action.
[UIView animateWithDuration:0.5 delay:0.2 options:(UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAllowUserInteraction) animations:^{
// Mostly fade out the number button label.
((UIButton *)_buttons[num]).alpha = 0.2;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.5 delay:0.2 options:(UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAllowUserInteraction) animations:^{
// Fade in the number button label.
((UIButton *)_buttons[num]).alpha = 1.0;
} completion:^(BOOL finished) {
// Stop the animation if the BOOL
// is set to 'NO' animations.
if (anim_state_button == NO) {
return;
}
}];
}];
}
谢谢,丹。
【问题讨论】:
-
试试
[self.view removeAllAnimations]; -
@Mrunal 出现错误,我不知道
removeAllAnimations方法在self.view上可用。
标签: ios objective-c animation uiviewanimation animatewithduration