1
我有一個使用UIPanGestureRecognizer的非常奇怪的問題。我使用識別器在SceneView中旋轉3D模型或相機。UIPanGestureRecognizer的翻譯在iPad中始終爲零
識別器適用於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
}
}