1

I'm drawing a MKMapView in my iOS app, and on this map are some annotations, with custom images representing them. The image changes slightly (has a glow) when a specific annotation is selected.

To do this, I'm using the mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!) delegate method to change the image (by changing view.annotation.image). This seems to work fine.

However, when I use the mapView(mapView: MKMapView!, didDeselectAnnotationView view: MKAnnotationView!) method to change the image back after it's deselected, it redraws the annotation in the upper left corner of the map. Any user interaction with the map then redraws it in its proper place immediately, so it's like the map isn't being refreshed after the method call until a click or something is made.

Is this actually the correct way to change an annotation's image (by overwriting the current view.annotation.image, and if so is there a way to refresh the map?

EDIT: I've also just noticed every time I select a new annotation it drags the map center down by about 100 pixels. Is there something I'm missing that I need to do after calling either of these two methods mentioned above?

fanfan
  • 504
  • 1
  • 4
  • 13

1 Answers1

1

You could try removing and re-adding the annotation using mapView.removeAnnotation(yourAnnotation) and mapview.addAnnotation(yourAnnotation) with the new image

Jona
  • 1,023
  • 2
  • 15
  • 39