Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        5年前关闭。
                                                                                            
                
        
我在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

最佳答案

这是removeAnimationForKey:的签名

- (void)removeAnimationForKey:(NSString *)key


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

10-07 23:40