[英]Stopping all animations in place on MKMapView Swift 3 iOS
在過去的一天中,我一直在這個問題上停留。 我創建了一個自定義MKAnnotation子類,以在MKMapView上顯示各種自定義引腳。 我遞歸地調用一個函數,使這些圖釘始終圍繞地圖移動。 我的目標是當用戶點擊按鈕時將所有這些動畫停止在適當的位置。 我努力了
self.view.layer.removeAllAnimations()
和
self.map.layer.removeAllAnimations()
和其他駭人聽聞的解決方案,但似乎無濟於事。
以下是創建動畫/圖釘運動的代碼
func animate(duration:Double, newLocation:CLLocationCoordinate2D){
UIView.animate(withDuration: duration, animations: {
self.coordinate = newLocation
}) { (done) in
self.finished_segment()
}
}
任何建議,不勝感激。
對於陷在這個問題上的任何人。 問題是我必須從與注釋關聯的MKAnnotationView中刪除動畫。 我基本上在自定義類中創建了一個成員變量,該自變量類是在mapView注釋委托方法中設置的,如下所示。
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "annotationView") ?? MKAnnotationView()
if let a = annotation as? Alien{
annotationView.image = a.image
a.annotationView = annotationView
}
return annotationView
}
並從地圖上刪除動畫。 只需致電
self.annotationView.layer.removeAllAnimations()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.