I am having an issue with iOS CABasicAnimation
. No matter what I do, I cannot get the methods animationDidStart:
and animationDidStop:finished:
to fire. My class is subclassing CAShapeLayer
and is performing the animations inside of it:
- (void)start{
[self removeAllAnimations];
CABasicAnimation *pathAnimation = [self makeAnimationForKey:@"strokeEnd"];
[self addAnimation:pathAnimation forKey:@"strokeEnd"];
}
- (CABasicAnimation *)makeAnimationForKey:(NSString *)key {
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:key];
anim.fromValue = [NSNumber numberWithFloat:0.f];
anim.toValue = [NSNumber numberWithFloat:1.f];
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
anim.duration = self.duration;
anim.delegate = self;
return anim;
}
- (void)animationDidStart:(CAAnimation *)anim{
NSLog(@"HERE START");
}
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
NSLog(@"HERE STOP");
}
Any tips or help would be appreciated, thanks in advance!
you must set delegate before assigning animation to layer:
popIn.delegate = self;
[annotation.layer addAnimation:popIn forKey:@"popIn"];
Ok so it turns in my subclass I had a property called duration. Even though it is not documented as being apart of CALayer
, duration is a part of one of it's protocols called CAMediaTiming
. The methods were never fired because the property was being overwritten via my subclass.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.