CALayer removeAnimationForKey:抛出CABasicAnimation长度:发送到实例的无法识别的选择器

时间:2014-02-24 14:43:06

标签: ios ios7 core-animation cabasicanimation caanimation

我在CALayer上有一个类别,用于添加和删除动画。我有一个完美的旋转动画,我有一个-endRotating方法。以下是我实施它的方法:

CAAnimation *anim = [self animationForKey:ROTATION_KEY];
if(anim){
    [self removeAnimationForKey:anim];
}

anim是方法中CABasicAnimation的一个实例,这是正确的。但是,[self removeAnimationForKey:anim];会将无法识别的选择器发送到我的动画实例:

-[CABasicAnimation length]: unrecognized selector sent to instance 0xba2bf40

这是UIKit中的错误,还是我做错了什么?

这是我的动画供参考:

-(void)beginRotatingWithAngularVelocity:(float)velocity{
    CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    rotationAnimation.fillMode = kCAFillModeForwards;
    rotationAnimation.removedOnCompletion = YES;
    rotationAnimation.repeatCount = 999999;
    rotationAnimation.duration = velocity;
    rotationAnimation.cumulative = YES;
    rotationAnimation.fromValue = [NSNumber numberWithFloat:0];
    rotationAnimation.toValue = [NSNumber numberWithFloat:M_PI * 2];
    [self addAnimation:rotationAnimation forKey:ROTATION_KEY];
}

为什么remove方法试图访问我动画的length

1 个答案:

答案 0 :(得分:2)

这是removeAnimationForKey:

的签名
- (void)removeAnimationForKey:(NSString *)key

正如您所看到的,它需要一个NSString对象(在您的情况下可能是ROTATION_KEY),而不是CAAnimation