我试图创建一个测试应用程序,用户可以通过点击SceneView来暂停动画。 SceneView从3D应用程序(Cinema 4D)中创建的.dae文件加载动画。该应用成功播放并在发布后循环播放动画。暂停SceneKit动画
要暂停动画,我用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的速度设置为零,但这也没有效果。什么是暂停正在进行的动画的正确方法?
更新死链接:[技术Q&A QA1673(https://developer.apple.com/library/content/qa/qa1673/_index.html) – edenwaith