在iOS 3中有什么方法可以停止动画吗?

我知道:

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


,但仅适用于iOS 4.0

最佳答案

尝试使用以下代码:

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...


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

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

08-18 10:19