当允许动画运行时,我有一个CAKeyframeAnimation调用animationDidStart:和animationDidStop:finished:,正如预期的那样。
当我在中断期间暂停动画时(调用,按下home btn等)animationDidStop:finished:按照预期触发标记为NO。
但是,重新启动暂停的动画后,animationDidStart:和animationDidStop:finished:永远不会再次触发。动画在视觉上继续并完成,但我没有收到该事件。我需要知道动画什么时候停止,所以我可以重新启动游戏循环。
我跟着this暂停/重启动画。
请告诉我我做错了什么。谢谢!
- (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, flag is: %d", flag);
}