iPad

时间:2017-01-01 09:12:47

标签: swift rotation scenekit uipangesturerecognizer

我对UIPanGestureRecognizer有一个非常奇怪的问题。我使用识别器在SceneView中旋转3D模型或相机。

识别器适用于iPhone。但是,如果我在iPad(物理或模拟器)上启动应用程序,识别器会被识别,但转换始终为零。

为什么?再次,iPhone运作良好。这是一个错误吗?

识别器创建:

// Model Rotation
let rotationRecognizer = UIPanGestureRecognizer(target: self, action: #selector(self.rotationRecognized(sender:)))
rotationRecognizer.minimumNumberOfTouches = 1
rotationRecognizer.maximumNumberOfTouches = 1
self.view.addGestureRecognizer(rotationRecognizer)

事件处理程序:

// MARK: Rotation of Model and Camera
func rotationRecognized(sender: UIPanGestureRecognizer) {
    if sender.state == .began {
        let translation = sender.translation(in: self.sceneView)
        Swift.print(translation)

        if abs(translation.x) > 0 {
            self.rotationMode = .model
        } else if abs(translation.y) > 0 {
            self.rotationMode = .camera
        }
    } else if sender.state == .changed {
        let translation = sender.translation(in: self.sceneView)

        if self.rotationMode == .model {
            if rootNode != nil {
                var newAngleY = Float(translation.x / 4) * Float(M_PI / 180.0)
                newAngleY += currentYAngle
                rootNode!.eulerAngles.y = newAngleY
            }
        } else if self.rotationMode == .camera {
            if cameraNode != nil {
                var newAngle = Float(translation.y / 4) * Float(M_PI / 180.0)

                if translation.y < 0 { // Up 
                    if Math.toDegrees(Double(newAngle + currentXAngle)) < -70 {
                        return
                    }
                } else if translation.y > 0 { // Down 
                    if Math.toDegrees(Double(newAngle + currentXAngle)) > -10 {
                        return
                    }
                }

                newAngle += currentXAngle
                cameraNode!.eulerAngles.x = newAngle
            }
        }
    } else if sender.state == .ended {
        if self.rotationMode == .model {
            if rootNode != nil {
                currentYAngle = rootNode!.eulerAngles.y
            }
        } else if self.rotationMode == .camera {
            if cameraNode != nil {
                currentXAngle = cameraNode!.eulerAngles.x
            }
        }

        self.rotationMode = .none
    }
}

1 个答案:

答案 0 :(得分:1)

yii\bootstrap\BootstrapPluginAsset