2015-01-21 86 views

回答

-1

最简单的方法是nilMKMapView的委托,以便在它之后不会调用委托方法。

self.mapView.delegate = nil; 
0

有一两件事你可以尝试创造一个CADisplayLink被拴在屏幕刷新频率,然后在其回调,检查地图的当前状态。在那里您可以调用另一个setRegion:animated:到当前位置以停止以前的动画。

2

如果您创建另一个动画,但是与现有区域不同的区域,则会使现有动画失效。注意:如果我尝试创建一个新的动画,但是对于visibleMapRect,iOS将会忽略它。

func stopZoom() { 
    //the trick: creating a region very similar to the existing one 
    var mapRegion:MKCoordinateRegion = MKCoordinateRegionForMapRect(self.mapView.visibleMapRect) 
    mapRegion.span.latitudeDelta = mapRegion.span.latitudeDelta + 0.000001 

    UIView.animateWithDuration(0.1, delay: 0.0, options: [], animations: { 
    let mapRegion:MKCoordinateRegion = mapRegion 
    self.mapView.setRegion(mapRegion, animated: true) //this will invalidate the other animations 
    }) { (completed: Bool) -> Void in 
} 

}

,以供参考startZoom方法:

func startZoom() { 
    UIView.animateWithDuration(10, delay: 0.0, options: [UIViewAnimationOptions.CurveLinear, UIViewAnimationOptions.AllowUserInteraction, UIViewAnimationOptions.BeginFromCurrentState], animations: { 
    let mapRegion:MKCoordinateRegion = MKCoordinateRegionMakeWithDistance(self.coordinate, 500, 500) 
    self.mapView.setRegion(mapRegion, animated: true) 
    }) { (completed: Bool) -> Void in 
} 

}

花相当多的时间来弄清楚这一点,我希望这将是对你有所帮助。