ユーザーが SceneView をクリックしてアニメーションを一時停止できるテスト アプリを作成しようとしています。SceneView は、3d アプリ (Cinema 4D) で作成された .dae ファイルからアニメーションを読み込みます。アプリは、起動時にアニメーションを正常に再生およびループします。
アニメーションを一時停止するには、Technical Q&A QA1673を参考にしました。この .dae ファイルの場合、アニメーションは実際にはアニメーションの階層として入ってくるので、基礎となる CAKeyframeAnimation のそれぞれに到達して、その速度をゼロに設定しようとしました。私のコードは現在次のようになっています。
- (void)mouseDown:(NSEvent *)event {
SCNNode *cubeNode = [self.scene.rootNode childNodeWithName:@"C4D_Cube" recursively:YES];
CAAnimation *cubeAnimation = [cubeNode animationForKey:@"Cube_Anim_01-02-1"];
CAAnimationGroup *cubeAnimationGroup = (CAAnimationGroup *)cubeAnimation;
// cubeAnimationGroup contains 3 CAAnimationGroups, each of which contains a CAKeyframeAnimation.
// So I directly access each CAKeyframeAnimation and set its speed to zero.
for (CAAnimationGroup *subGroup in [cubeAnimationGroup animations]) {
CFTimeInterval pausedTime = CACurrentMediaTime();
[[subGroup animations] setValue:@0.0 forKey:@"speed"];
[[subGroup animations] setValue:[NSNumber numberWithFloat:pausedTime] forKey:@"timeOffset"];
}
}
ブレークポイントを設定すると、キーフレーム アニメーションの速度が 1 から 0 に変化することがわかりますが、アニメーションはシーン ビューで通常の速度で再生され続けます。私はもともと最上位の CAAnimationGroup の速度をゼロに設定しようとしましたが、これも効果がありませんでした。進行中のアニメーションを一時停止する正しい方法は何ですか?