I am using swift for an ios app, and it (of course) uses various gesture recognizers. I have not had too many problems with them up until now: I am using a UILongPressGestureRecognizer, and I think it is configured correctly (I just looked in the documentation and set my instance of UILongPressGestureRecognizer to reasonable values). The problem is that its selector function is not running. Here is my code.
let longPress : UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPressAction(sender:)))
longPress.allowableMovement = 20
longPress.minimumPressDuration = 0.5
longPress.numberOfTapsRequired = 0
longPress.numberOfTouchesRequired = 1
self.view.isUserInteractionEnabled = true
self.view.addGestureRecognizer(longPress)
print("self.view gesture recognizers: \n")
print(self.view.gestureRecognizers as Any)
I have messed around a little with all the values for the configuration (i.e. numberOfTapsRequired). And here is my selector function/action:
@objc func longPressAction(sender : UIGestureRecognizer) {
print("Long Press Recieved")
//Other code here
}
Here is the developer page for UILongPressGestureRecognizer: https://developer.apple.com/documentation/uikit/uilongpressgesturerecognizer
Thanks for any help, and if you need any clarification about what I am doing, please ask.