Search code examples
swiftimageannotationsmapkitios14

iOS 14 MapKit selected annotation image bug


First of all, I encountered a problem that only came with iOS 14. I do not have such a problem with old versions.

I change the image of the pin when I chose from the pins on the map and throw an orange picture. While doing this assignment, I see some of the assets I use in the application during this change on iOS 14 devices.

First appearance:

Before

The moment the pin is selected:

During

After the pin is selected:

After

When the pin is selected, the assets do not appear normally, the pin was selected directly. Now, such a situation intervened.

The codes I use in pin click situations on the map are as follows

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
    view.image = UIImage(named: "pin_selected")
}

func mapView(_ mapView: MKMapView, didDeselect view: MKAnnotationView) {
    view.image = UIImage(named: "pin")
}

It is a situation that passes in seconds, but how can I solve this problem?


Solution

  • I had the same issue, and after struggling a lot I realize it was a problem with the image. Probably some left metadata in the image cause the issue when the annotation animates between states. What I did was having the image for the annotation to be exported again from designs and replaced in the project, and that solved the issue.