This is my first time using UI Gesture Recognizers. I am trying to implement it into SceneKit
, to control the camera (isn't there a better way for custom controls?).
Here is a glimpse of what I have in my 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!")
}
I can see that my Pan
gesture works perfectly fine. However, my Swipe
gesture does not seem to work at all. Removing the Pan
gesture did not do anything, so there isn't a problem with the gestures fighting over priority.
Why is this not recognising my gestures? Have I forgotten some crucial things (like a delegate)?
I just realised that when I set up my view, I set the camera control as such:
gameView.allowsCameraControl = true // Camera control
when it should really be:
gameView.allowsCameraControl = false // Camera control
I assume this is because the camera is overriding the gestures to the view, and I completely forgot about this! Works well as expected now, and hope it helps anyone in the future who also made this same small mistake.