这是我第一次使用UI手势识别器。我正在尝试将其实现到 SceneKit
中,以控制相机(是否有更好的自定义控件方法?)。
这是我的 View Controller 中的内容的一瞥:
var gameView: SCNView!
/* ... */
override func viewDidLoad() {
super.viewDidLoad()
// Setup game
/* ... */
// Gestures
let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(swipeRightGesture))
swipeRight.direction = .right
gameView.addGestureRecognizer(swipeRight)
let pan = UIPanGestureRecognizer(target: self, action: #selector(panGesture))
gameView.addGestureRecognizer(pan)
}
@objc func swipeRightGesture() {
print("SWIPE!")
}
@objc func panGesture() {
print("PAN!")
}
我可以看到我的平移
手势工作得很好。但是,我的 Swipe
手势似乎根本不起作用。删除平移
手势没有执行任何操作,因此手势争夺优先级不存在问题。
为什么它无法识别我的手势?我是否忘记了一些重要的事情(例如代表)?
最佳答案
我刚刚意识到,当我设置 View 时,我将相机控制设置为这样:
gameView.allowsCameraControl = true // Camera control
当它真正应该是:
gameView.allowsCameraControl = false // Camera control
我认为这是因为相机覆盖了 View 的手势,而我完全忘记了这一点!现在效果符合预期,希望它对将来也犯同样小错误的人有所帮助。
关于ios - 滑动手势无法识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53542481/