I have set up a UILongPressGestureRecognizer that works fine in versions before IOS 13, but in this version to detect the second long press, I have to press twice.
That is to say:
1º LongPress -> Work Fine show "long tap"
2º LongPress -> Not work
3º LongPress -> Work Fine show "long tap"
4º LongPress -> Not work
...
This is my code.
let longTapGesture = UILongPressGestureRecognizer(target: self, action: #selector(longTap))
longTapGesture.delegate = self
longTapGesture.numberOfTouchesRequired = 1
longTapGesture.cancelsTouchesInView = false
mapView.addGestureRecognizer(longTapGesture)
Function called is:
@objc func longTap(sender: UIGestureRecognizer){
print("long tap")
.....
}
The solution to this is to allow for simultaneous gestures. Simply set the long press gesture's
delegateand implement the following delegate method:That's it. The long press gesture on the map view will now work every time.
As a demonstration, create a new iOS project based on Swift and storyboard. Replace the provided
ViewController.swiftimplementation with the following:Do note that
shouldRecognizeSimultaneouslyWithwill get called quite a few times. There seems to be at least 3 other gestures, including another long press gesture that expects two touches. So it's probably best not to setup your own long press gesture to require two touches.