Animated View Annotations Fade When Map Scales?

I add CABasicAnimation to the AnnotationView layer to simulate a car moving on a map.

This works fine until I try to zoom in or out while animating.

I found that the animated annotator disappears when the map is scaled.

I suppose this could be because the layer associated with the animation object was removed when the mapview was scaled.

I am trying to solve this problem by stopping the animation while scaling. but the result is not very good. The car seems to be jumping to the target point.

Anyone have any ideas on this?

Does anyone know how to make the animation still run when the map is scaled?

+8
ios animation mkmapview cabasicanimation mkannotationview
source share
3 answers

I don’t know how to solve your problem programmatically, but what if you save the car’s position (point a) directly, when the user starts to zoom in, when the scale is completed, calculate the distance between the current position and the new position (point b), and then animate it from point a to point b. Thus, the car will not swim to β€œjump” to the second target point. To make this a bit strange, start the vehicle at twice normal speed and then slow down to normal speed when you get to point β€œB”. I think this will make it less like an error and more like an effect.

+1
source share

I solved it by completing all annotation animations on regionWillChangeAnimated: -

 - (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated { for (int i=0;i< [mapView.annotations count];i++) { id annotation = [mapView.annotations objectAtIndex:i]; MKAnnotationView* annView =[mapView viewForAnnotation: annotation]; if (annView != nil) { CALayer* layer = annView.layer; [layer removeAllAnimations]; } } } 
+1
source share

I think you can use the delegate method mapView:regionDidChangeAnimated: Each time the user scrolls / zooms in, this method will be called. just try once. It can help you.

0
source share

All Articles