在一段时间后通过代码修改 sceneView.pointOfView 属性时,更新的 pointOfView 值不会立即影响 3D 模型,直到发生点击或与模型交互。为什么会出现这种行为?我们该如何解决这个问题?
我更新pointOfView的代码:
import SceneKit
func setupScene() {
guard let scene = SCNScene(named: mockup.fileName) else {
print("Unable to load scene file.")
return
}
sceneView.allowsCameraControl = true
sceneView.backgroundColor = .clear
sceneView.autoenablesDefaultLighting = true
sceneView.isJitteringEnabled = true
sceneView.isPlaying = false
sceneView.scene = scene
// If we update the point of view directly, there is no problem.
//updatePointOfViewAfter(seconds: 0)
// Updating after a few seconds will not take effect unless the user taps or interacts with the 3D model.
updatePointOfViewAfter(seconds: 3)
}
func updatePointOfViewAfter(seconds: Double) {
DispatchQueue.main.asyncAfter(deadline: .now() + seconds) {
if let newPointOfView = self.sceneView.pointOfView {
newPointOfView.position = SCNVector3(x: newPointOfView.position.x + 10,
y: newPointOfView.position.y + 10,
z: newPointOfView.position.z + 10)
self.sceneView.pointOfView = newPointOfView
}
}
}
我不太确定,但在这里尝试一下(在场景视图配置期间)
sceneView.rendersContinuously = true