2015-01-21 88 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 
} 

}

花相當多的時間來弄清楚這一點,我希望這將是對你有所幫助。