9

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?

Pfitz
  • 7,336
  • 4
  • 38
  • 51
Hubert
  • 91
  • 2

3 Answers3

1

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.

Beleg
  • 362
  • 2
  • 23
  • Good ideas, but I really need an answer with working code. I don't even know how to detect when the user is zooming in the MKMapView. – Felix Jul 24 '12 at 15:18
1

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

  }
}
goelectric
  • 320
  • 3
  • 10
0

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

parilogic
  • 1,147
  • 9
  • 26