Reputation: 1
I am writing an app that displays a set of thumbnail images on a map. When I need to display a new thumbnail I dequeue a map annotationview using dequeueReusableAnnotationViewWithIdentifier. I then change the annotationview image. There appears to be an animation effect that fades from the image that was used by the previous use of the annotationview to the newly assigned image. Is there an easy way to just display the new image without the animation.
In:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation)
I have tried:
MKAnnotationView(annotation: annotation, reuseIdentifier: nil)
i.e. create a new annotation view that will not be reused after it is scrolled off the screen or is removed by the app. This resolves the problem but annotation views will never be available for dequeueReusableAnnotationView. For performance reasons this is not recommended but it fixes my problem! Is this the only solution?
Upvotes: 0
Views: 332
Reputation: 6849
In your MKAnnotationView subclass, you should have something like
override var annotation: MKAnnotation? {
willSet {
...
}
}
In case an MKAnnotationView
instance is not needed any more, MapKit sets annotation = nil
.
This is an excellent time in willSet
to clean up the objct: set the image to nil, maybe set other properties that you use to nil also.
If you are doing it this way, there should be no image referenced that could be shown.
Upvotes: 0