I would like to capture taps on an MKMarkerAnnotationView
, and not animate the view when this happens.
Through a delegate for my MKMapView
, I can capture selection and deselection that are roughly equivalent to taps on the MKMarkerAnnotationView
(the selection also happens when tapping the label that is not part of the MKMarkerAnnotationView
)
I am trying to remove the default animation. I didn't find a straightforward solution.
I tried:
1/ setting the view to not selected during the selection. This does cancel the animation but further taps are not captured.
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
view.setSelected(false, animated: false)
// or
view.isSelected = false
handleTap(view)
}
2/ adding another tap gesture recognizer on the view and preventing other gesture recognizers from receiving the touch. This works well unless I tap the label instead of the annotation view.
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let view = dequeueReusableAnnotationView(withIdentifier: reuseIdentifier) as? MKMarkerAnnotationView ??
MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: reuseIdentifier)
view.annotation = annotation
view.gestureRecognizers?.forEach { view.removeGestureRecognizer($0) }
let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(didTap(gesture:)))
gestureRecognizer.delegate = self
view.addGestureRecognizer(gestureRecognizer)
return view
}
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return false
}