Animated AnnotationView disappears while zooming the mapview?
Asked Answered
A

3

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?

Ahab answered 11/7, 2012 at 9:6 Comment(2)
Did you make any progress on this problem? I am experiencing the same issue and would like to solve it.Gomphosis
@Ahab can you post your code of moving annotation?Phenolic
A
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.

Alanaalanah answered 24/7, 2012 at 14:42 Comment(1)
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.Melvinmelvina
S
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];
    }

  }
}
Staggs answered 19/10, 2012 at 13:16 Comment(0)
K
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.

Kef answered 30/7, 2012 at 11:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.