简体   繁体   English

如何在 SceneView SwiftUI 中暂停/播放 animation

[英]How to pause/play animation in SceneView SwiftUI

I am trying to pause and resume the animation of a 3D scene in SwiftUI, using isPaused but not sure why it doesn't pause or resume the scene's animation. I am trying to pause and resume the animation of a 3D scene in SwiftUI, using isPaused but not sure why it doesn't pause or resume the scene's animation. Here is the code:这是代码:

var scene: SCNScene? {
        let scene = SCNScene(named: "model.dae")
        scene?.rootNode.scale = SCNVector3(0.6, 0.6, 0.6)
        return scene
    }

var body: some View {

     VStack {

          SceneView(
                scene: scene,
                pointOfView: cameraNode,
                options: [.allowsCameraControl, .autoenablesDefaultLighting]
                )


  Button("Pause") {
      scene?.isPaused = false 
    }

  }
}

I tried scene?.rootNode.isPaused but still nothing happened, any help would be great.我尝试了scene?.rootNode.isPaused但仍然没有发生任何事情,任何帮助都会很棒。

I do it like this:我这样做:

to pause:暂停:

sceneView.scene?.rootNode.isPaused = true
sceneView.scene?.isPaused = true
sceneView.isPlaying = false

to un-pause:取消暂停:

sceneView.isPlaying = true
sceneView.scene?.isPaused = false
sceneView.scene?.rootNode.isPaused = false

Hopefully this will work for you.希望这对你有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM