presentationNode的位置正在重置

时间:2016-05-04 08:50:58

标签: ios swift gesture scenekit

我首先使用UIPinchGestureRecognizer和applyForce向前或向后移动一个物理主体。然后我使用UIRotationGestureRecognizerSCNAction来轮换其节点。物体向前移动并旋转,但在旋转发生之前,物体会跳回(节点的)起始位置。 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)
}

1 个答案:

答案 0 :(得分:1)

我通过更新渲染器委托方法中的位置来解决它:

func renderer(renderer: SCNSceneRenderer, updateAtTime time:   NSTimeInterval) {
    self.cameraNode1.position = self.cameraNode1.presentationNode.position
    self.cameraNode1.rotation = self.cameraNode1.presentationNode.rotation
}