This is how MKMarkerAnnotationView
annotations look in iOS 15 in my app.
The markers on the beach only consist of an image no bubble from the MKMarkerAnnotationView
With iOS 16 beta 3, many but not all images are hidden by the marker bubble; colors appear to be random.
MKMarkerAnnotationView
is set like this:
self.glyphImage = myImage
self.glyphText = ""
self.glyphTintColor = UIColor.clear
self.markerTintColor = UIColor.clear
I checked in the debugger that this code is executed.
What is the cause and how can I prevent the bubbles from hiding the image?
3
Answers
The colors of the bubbles are colors that are used elsewhere in the app.
The following workaround fixes the problem:
in
public func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {...}
replace
mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
and create a fresh instance ofMKMarkerAnnotationView
or your subclass ofMKMarkerAnnotationView
.This is a bad workaround since
mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
is there for a reason, the workaround should have worse performance.The nature of the workaround suggests a bug in Apples implementation that the internal representation of the bubble is created only once or created only once if
UIColor.clear
is used.Let's hope Apple fixes this until iOS 16 or someone comes up with a better answer.
App with workaround and iOS 16 beta 3:
Be aware that this workaround only helps in the case where the bubble always is invisible. It does not help in the case if you want the bubble sometimes visible and sometimes invisible vor the same annotation.
My application primary feature is map and occur this problem too.
The perfect solution that I found is set different identifier for same view class with different annotation type.
Example:
The use
dequeueReusableAnnotationView(withIdentifier:for:)
to dequeue different type annotation view in different case.In iOS 16 every time you set the MKAnnotationView image, the glyph resets. So every time you update your image you also need to clear the glyph.