In my iOS app I have an instance of an MKMapView
and on single tap, I want to add a marker to the map. I've added a UITapGestureRecognizer
and immediately noticed that it would fire even when a user double taps to zoom (or other interactions with the map).
I've implemented the UIGestureRecognizerDelegate
method like this and this works, but makes the interaction very sluggish, because it obviously waits for the other gesture recognizers to fail.
func gestureRecognizer(
_ gestureRecognizer: UIGestureRecognizer,
shouldRequireFailureOf otherGestureRecognizer: UIGestureRecognizer
) -> Bool {
guard gestureRecognizer == self.mapGestureRecognizer else {
return false
}
return !(otherGestureRecognizer is UITapGestureRecognizer) && otherGestureRecognizer.state == .possible
}
Is there any way to act quickly on a tap, without breaking the native gestures on the map view?