アニメーションがそのコースを実行できるようになったときに、animationDidStart: と animationDidStop:finished: を呼び出す CAKeyframeAnimation があります。
中断中にアニメーションを一時停止すると (通話、ホームボタンが押されたなど)、animationDidStop:finished: が NO のフラグで発生します。
ただし、一時停止したアニメーションを再開した後、animationDidStart: と animationDidStop:finished: が再び起動されることはありません。アニメーションは視覚的に継続して完了しますが、イベントが表示されません。ゲームループを再開できるように、アニメーションがいつ停止するかを知る必要があります。
アニメーションの一時停止/再開のためにこれに従いました。
私が間違っていることを教えてください。ありがとう!
- (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);
}