Paused/restarted animation does not call delegate methods
I have a CAKeyframeAnimation that calls animationDidStart: and animationDidStop:finished:, as expected, when the animation is allowed to run its course.
When I pause the animation during interruptions (calls, home btn pressed, etc) animationDidStop:finished: fires with a flag of NO, as expected.
However, after restarting the paused animation, animationDidStart: and animationDidStop:finished: are never fired again. The animation does visually continue and complete, but I don't receive the event. I need to know when the animation stops so I can restart my game loop.
I followed this for the pause/restart of the animation.
Please tell me what am I doing wrong. Thanks!
- (void)takeFlight
{
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.removedOnCompletion = NO;
pathAnimation.duration = FLY_ANIM_TIME;
pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
pathAnimation.delegate = self;
CGPoint endPoint = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/3);
CGMutablePathRef curvedPath = CGPathCreateMutable();
CGPathMoveToPoint(curvedPath, NULL, xPos, yPos);
CGPathAddQuadCurveToPoint(curvedPath, NULL, -100.0, -50.0, 200.0, 100.0);
pathAnimation.path = curvedPath;
CGPathRelease(curvedPath);
[shipView.layer addAnimation:pathAnimation forKey:@"flyin"];
shipView.center = endPoint;
}
-(void)pauseFlight
{
CALayer *layer = (CALayer *)shipView.layer;
CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
layer.speed = 0.0;
layer.timeOffset = pausedTime;
}
-(void)resumeFlight
{
CALayer *layer = (CALayer *)shipView.layer;
CFTimeInterval pausedTime = [layer timeOffset];
layer.speed = 1.0;
layer.timeOffset = 0.0;
layer.beginTime = 0.0;
CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
layer.beginTime = timeSincePause;
}
- (void)animationDidStart:(CAAnimation *)animation
{
NSLog(@"anim did start");
}
- (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)flag
{
NSLog(@"anim did stop开发者_JAVA技巧, flag is: %d", flag);
}
精彩评论