Change annotation image after creating it

I have a custom annotation that sets its image depending on the type of annotation using the viewForAnnotation delegate method. Im uses only 1 annotation, which is a moving car and wants to change the image when the car is detected to move and stop. How can I do this, other than deleting my annotation and re-adding it, which causes a blink?

+5
source share
1 answer

When you find that the state of the car has changed, retrieve the view of the current annotation using the instance method MKMapView viewForAnnotation:. This is not the same as the delegate method mapView:viewForAnnotation:.

, image.

, mapView:viewForAnnotation: , image . , ( ), .

, , :

//carAnnotation is your id<MKAnnotation> object
MKAnnotationView *av = [mapView viewForAnnotation:carAnnotation];
if (carAnnotation.isMoving)
    av.image = [UIImage imageNamed:@"moving.png"];
else
    av.image = [UIImage imageNamed:@"stopped.png"];

if ( , image) - , viewForAnnotation.

+10

All Articles