你能帮帮我吗?我需要停止 MkMapView 方法 setRegion:region animated: true。我需要设置新区域动画并选择停止它。 谢谢。
最佳答案
如果您创建另一个动画但针对与现有动画不同的区域,这将使现有动画无效。注意:如果我尝试创建一个新动画,但对于相同的 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
}
花了很多时间弄明白了,希望对你有所帮助。
关于ios - MKMapView setRegion 如何停止动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28066239/