Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animated AnnotationView disappears while zooming the mapview?

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?

like image 920
Hubert Avatar asked Jul 11 '12 09:07

Hubert


2 Answers

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.

like image 160
Beleg Avatar answered Oct 18 '22 21:10

Beleg


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];
    }

  }
}
like image 24
goelectric Avatar answered Oct 18 '22 20:10

goelectric