I add a CABasicAnimation
to the AnnotationView
layer to simulate a car moving on the mapview.
This works fine until I try to zoom in or out the mapview when the animation is in progress.
I found the animating annotation view disappears when zooming the mapview!!
I guess this may be caused by that the layer associated the animation object has been removed when zooming mapview.
I try to solve this by stopping the animation when zooming. but the result is not good. The car seems jump to target point.
Anyone has ideas about this?
Anyone knows how to make the animation still running when zooming the mapview?
I do not know how to solve your problem programmatically, but what if store the cars position (point a) right when the user starts to zoom, when the zoom is complete, calculate the distance between the current position and the new position (point b) and then animate it from point a to point b. This way the car would not seam to "jump" to the second target point. To make it a little fancier, start the car's speed at twice the normal speed and then decelerate to normal speed as you get closer to point "B". I think this will make it look less like a bug and more like a effect.
I solved it by terminating all the 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];
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With