通过函数调用停止由用户交互触发的 SceneView 动画

问题描述 投票:0回答:2

当用户更改场景视图的视点的位置、方向、旋转或变换(allowsCameraControl 为 true)时,他们可以通过单击场景视图来停止此操作。如何通过函数调用来实现这一点?

swift scenekit
2个回答
0
投票

如果您的目标是通过函数调用来停止

POV
allowsCameraControl
的自动旋转,您可能可以这样做。

(在这个基本示例中:0.5秒后停止运动)

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
        self.cameraNode.transform = self.scnView.pointOfView!.transform
        self.scnView.pointOfView = self.cameraNode
    }
}

我不知道这是否正是您想要实现的目标,但它会停止相机旋转。

(自动旋转来自于SceneKit内部生成的相机对象,当

allowsCameraControl
设置为true时,实际上移动或旋转的并不是cameraNode。)


0
投票

这段代码就可以解决问题:

sceneView.defaultCameraController.inertiaEnabled = false
sceneView.defaultCameraController.inertiaEnabled = true
© www.soinside.com 2019 - 2024. All rights reserved.