Here's the signature of removeAnimationForKey:
- (void)removeAnimationForKey:(NSString *)key
As you can see it expects an NSString
object (in your case probably ROTATION_KEY
), not a CAAnimation
.
Frage
I have a category on CALayer
that adds and removes animations. I have a rotation animation that works perfectly and I have an -endRotating
method. Here is how I've implemented it:
CAAnimation *anim = [self animationForKey:ROTATION_KEY];
if(anim){
[self removeAnimationForKey:anim];
}
anim
is an instance of CABasicAnimation
in the method, which is correct. However, [self removeAnimationForKey:anim];
causes an unrecognized selector to be sent to my animation instance:
-[CABasicAnimation length]: unrecognized selector sent to instance 0xba2bf40
Is this a bug in UIKit, or am I doing something wrong?
Here is my animation for reference:
-(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];
}
Why is remove method trying to access length
of my animation?
Lösung
Here's the signature of removeAnimationForKey:
- (void)removeAnimationForKey:(NSString *)key
As you can see it expects an NSString
object (in your case probably ROTATION_KEY
), not a CAAnimation
.