I'm trying to add a swipe gesture recognizer to my view. Here's a snippet of code from my viewDidLoad()
method of the main view controller file:
self.view.addGestureRecognizer(UISwipeGestureRecognizer(target: self, action: #selector(self.swipeHandler(_:))))
self.view.isUserInteractionEnabled = true
And here's the handler method I wrote below the viewDidLoad()
function:
@IBAction func swipeHandler(_ gestureRecognizer : UISwipeGestureRecognizer) {
print("called")
if gestureRecognizer.state == .ended {
// Perform action.
print("ended")
}
}
When I swipe, no matter what the direction is, I don't see anything printed to the console.
I think the issue is with the addGestureRecognizerMethod()
because when I altered it to a tap recognizer (same exact line, just UITapGestureRecognizer instead of UISwipeGestureRecognizer), I get "called" and "ended" printed in the console.
Any tips?