如何在iOS中停止UIView动画< 4

时间:2012-07-05 07:36:32

标签: objective-c ios animation uiview

有没有办法在iOS 3中停止动画?

我知道:

 #import <QuartzCore/QuartzCore.h>
 [view.layer removeAllAnimations];   

,但它仅适用于iOS 4.0

1 个答案:

答案 0 :(得分:1)

尝试使用此代码:

if([view.layer repondsToSelector:@selector(removeAllAnimations)]) //Check if the CALayer responds to removeAllAnimations method for iOS4+
    [view.layer removeAllAnimations];
else
    [view.layer addAnimation:nil forKey:@"TheKeyOfTheAnimation"]; // Change TheKeyOfTheAnimation with key you have added animation for, you can also use nil for the key...

更新:根据文档,自iOS2.0起,removeAllAnimations可用 removeAllAnimations 删除附加到接收器的所有动画。

- (void)removeAllAnimations
Availability
Available in iOS 2.0 and later.
Declared In
CALayer.h