【问题标题】:CALayer removeAnimationForKey: throws CABasicAnimation length: unrecognized selector sent to instance [closed]CALayer removeAnimationForKey:抛出 CABasicAnimation 长度:无法识别的选择器发送到实例 [关闭]
【发布时间】:2014-02-24 14:43:05
【问题描述】:

我在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

【问题讨论】:

  • 这只是一个错字。您正在传递实际的动画对象而不是 key sat eh 参数。
  • 哎呀,我怎么看不到。谢谢。

标签: ios ios7 core-animation cabasicanimation caanimation


【解决方案1】:

这是removeAnimationForKey:的签名

- (void)removeAnimationForKey:(NSString *)key

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

【讨论】:

  • 我不知道为什么我传递的是动画而不是密钥。谢谢:)
猜你喜欢
  • 2015-03-02
  • 2015-09-09
  • 2014-05-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-24
相关资源
最近更新 更多