Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tap gesture for MapKit

Currently I have a map that has several Annotations.

For the Annotations I have

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView){
     // Do your annotation click work
}

Is it possible to do this for tapping the Map only and not the Annotation and how can I do it?

like image 464
Wesley Skeen Avatar asked Dec 10 '16 13:12

Wesley Skeen


1 Answers

In ViewWillAppear method :

let gestureRecognizer = UITapGestureRecognizer(target: self, action:"triggerTouchAction:")
mapView.addGestureRecognizer(gestureRecognizer)

And Whatever information you want to show just add code in following method :

func triggerTouchAction(gestureReconizer: UITapGestureRecognizer) {
      //Add alert to show it works
}

Hope it going to help you to resolve issue.

like image 177
Shobhakar Tiwari Avatar answered Sep 25 '22 23:09

Shobhakar Tiwari