Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 926
Hilalkah Avatar asked Sep 25 '20 11:09

Hilalkah


2 Answers

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.

like image 50
darkluink Avatar answered Oct 27 '22 11:10

darkluink


Ran into this issue as well. A fix that worked for me is to put the images in a Sprite Atlas: select the asset library in Xcode, press the + button on the lower left, select New Sprite Atlas, then drag the images in the asset library into the Sprites folder.

For me the issue was only happening with small PNG images. JPEGs or large PNGs (I tried 256x256 and scaled down) seemed to work fine. However I ended up using the above workaround since small PNGs are ideal for these map pin icons. The devices I tested were running iOS 14.0.1.

like image 2
J. Kevin Corcoran Avatar answered Oct 27 '22 10:10

J. Kevin Corcoran