0

I have an MKMapView with some annotations in it.

I have a MKMapViewDelegate, with a mapView(_:didSelect:) implementation. It works, but there's a noticeable lag. Between clicking the annotation, and receiving this message, there's about a half-second delay.

In other types of views, I catch click events, and they're instantaneous. On the map, there's only a couple annotations, and they just have a tiny amount of data -- not a performance bottleneck.

Is there any way to bypass the delay, and get the click event for MKMapView annotations right away? The delay isn't the end of the world, but it is pretty annoying.

Ssswift
  • 916
  • 10
  • 20

2 Answers2

0

You can try to declare your annotation's button like this:

let smallSquare = CGSize(width: 30, height: 30)  // The size of the button.
let button = UIButton(frame: CGRect(origin: CGPointZero, size: smallSquare))   // To initialize the button with the size.

button.addTarget(self, action: #selector(ViewController.a_function), forControlEvents: .TouchUpInside)
your_pinView.leftCalloutAccessoryView = button   
// I do not know how to use all the space of the view. 
// You can also do like this:
// your_pinView.rightCalloutAccessoryView = button 
// And add an image to bring out the button BEFORE SET THE BUTTON IN THE ANNOTATION like this:
// button.setBackgroundImage(UIImage(named: "car"), forState: .Normal)

Like this if the button is selected, the function a_function () (in my exemple) is called.

Your function should look like this:

func a_function () {

    print ("Annotation selected!"); 

}

I do not know if is it what you want but for my it works well with a short delay.

SphynxTech
  • 1,799
  • 2
  • 18
  • 38
  • I'm not quite sure what's going on here. You're using classes/methods/constants that don't exist on OS X. The docs say `leftCalloutAccessoryView` is for "providing custom callout views", and I'm not using callouts, either. I just want click events. – Ssswift Jan 26 '17 at 00:43
0

You should try referencing this post: I believe it's the same problem you're talking about with a working solution posted.

The problem has to do with the gesture recognizers that already exist on the annotation view. The answer in the above post suggests setting isZoomEnabled = false within a gesture recognizer on any click, then setting isZoomEnabled = true within the (didSelect) function of mapView.

Plato
  • 111
  • 2
  • 7