滑动手势无法识别

时间:2018-11-29 15:33:40

标签: ios swift uigesturerecognizer scenekit uiswipegesturerecognizer

这是我第一次使用 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!")
}

我可以看到我的Pan手势效果很好。但是,我的Swipe手势似乎根本不起作用。删除Pan手势不会没有做任何事情,因此手势优先级没有问题。

为什么这不能识别我的手势?我忘了一些重要的事情(例如代表)吗?

1 个答案:

答案 0 :(得分:0)

我刚刚意识到,设置视图时,我将相机控件设置为:

gameView.allowsCameraControl = true // Camera control

真正应该是:

gameView.allowsCameraControl = false // Camera control

我认为这是因为相机正在覆盖视图的手势,而我完全忘记了!现在可以按预期运行,并且希望它对将来也会犯同样小错误的人有所帮助。

相关问题