UIView animateWithDuration如何通过触摸事件取消(不与MapView交互)

时间:2016-10-12 13:12:40

标签: ios objective-c animation uiview

我的功能有问题。

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

如果还有位置,该功能将在列表中查找。如果是这样,它将再次运行。这样可行。唯一的问题是。如果动画正在运行。 mapView没有可能的交互。另一个问题是我找不到如何取消,停止或删除我的动画。

如果我把:

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

在completionBlock内部,我与地图进行了互动。但我不想那样做,因为我想在同一时间制作动画。在这里,我找不到取消动画的方法。

请不要说removeAllAnimation。这不起作用。

1 个答案:

答案 0 :(得分:1)

我相信this会回答你的问题。

基本上,您在同一目标上提交一个新动画,持续时间很短。通过设置setAnimationBeginsFromCurrentState标志可以防止奇怪的跳跃。