我首先使用UIPinchGestureRecognizer
和applyForce向前或向后移动一个物理主体。然后我使用UIRotationGestureRecognizer
和SCNAction
来轮换其节点。物体向前移动并旋转,但在旋转发生之前,物体会跳回(节点的)起始位置。 cameraNode1.presentationNode的位置正在更新,但在使用第二个手势监听器时它正在重置。为什么呢?
func handlePinch(recognizer: UIPinchGestureRecognizer) {
var dz = 5 * (1 - recognizer.scale)
self.cameraNode1.physicsBody?.applyForce(SCNVector3(0, 0, dz), impulse: true)
recognizer.scale = 1
}
func handleRotate(recognizer: UIRotationGestureRecognizer) {
let rot = -recognizer.rotation
recognizer.rotation = 0
let action = SCNAction.rotateByX(0, y: rot, z: 0, duration: NSTimeInterval(0))
self.cameraNode1.runAction(action)
}
答案 0 :(得分:1)
我通过更新渲染器委托方法中的位置来解决它:
func renderer(renderer: SCNSceneRenderer, updateAtTime time: NSTimeInterval) {
self.cameraNode1.position = self.cameraNode1.presentationNode.position
self.cameraNode1.rotation = self.cameraNode1.presentationNode.rotation
}