.began
state ends when user lifts the finger, so the accepted answer is not correct for this problem. After some time I figured it out.
Answer in Swift:
var gesture = UILongPressGestureRecognizer(target: self, action: #selector(longPress(_:)))
func handleLongPress(){
//do something
gesture.addTarget(self, action: #selector(longPress(_:)))
}
@objc func longPress(_ sender: UILongPressGestureRecognizer) {
if sender.state == .began {
handleLongPress()
gesture.removeTarget(self, action: #selector(longPress(_:)))
}
}
This will cause the gesture to stop tracking touch after .began
state is received and re-enable it after you finish doing whatever you want to do after long press
This is very old question but I hope someone will find it useful