1

I have a problem with my function.

[UIView animateWithDuration:5 animations:^{
    //set end coordinates for marker = MKAnnotationPoint
    [self.followDriverMarker setCoordinate:CLLocationCoordinate2DMake(latitde, longitude)];
    //set end coordinate for camera/map
    [self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(latitde, longitude) animated:NO];
  } 
  completion:^(BOOL finished) {
    if (finished) {
        if (self.currentPosition < [self.followDriverList count] - 2) {
            self.currentPosition++;
            //start next one
            [self runAnimation];
        } else {
            //animation is finished
            //TODO
            self.isAnimationRunning = NO;
        }
    }
}];

The function will look in a List if there are locations left. If so it will run again. That works. The only problem is. If the animation is running. There is no interaction possible with the mapView. The other problem is that i cannot find how to cancel,stop or remove my Animation.

If I put:

[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(latitde, longitude) animated:NO];

inside the the completionBlock, I have interaction with map. But I don't want to do that because I want to animate it the same time. Also here I can't find a way to cancel the animation.

Please don't say removeAllAnimation. This is not working.

Ozgur Vatansever
  • 49,246
  • 17
  • 84
  • 119
d.v.r.blok
  • 31
  • 4

1 Answers1

1

I believe this answers your question.

Basically you commit a new animation on the same target with a short duration. By setting the setAnimationBeginsFromCurrentState flag you prevent weird jumps.

Community
  • 1
  • 1
Thomm
  • 506
  • 5
  • 12
  • Thank you for reply. But this is not what i need. The problem is i have no interaction with the map. And i want to now how to stop a animation when it's animating. Stop/cancel/remove Animation must be called when scroll MapView or Touch. – d.v.r.blok Oct 17 '16 at 11:52
  • You achieve that by committing a new animation with a very short, or zero, duration. Basically it will override the existing animation, effectively stopping it. See [this](http://stackoverflow.com/a/841967/4019540). – Thomm Oct 17 '16 at 12:58