2017-05-20 5 views
0

私は過去1日、この問題を抱えていました。カスタムのMKAnnotationサブクラスを作成して、MKMapViewにさまざまなカスタムピンを表示しました。私は再帰的にマップの周りにこれらのピンのアニメーションを維持する関数を呼び出します。私の目標は、ユーザーがボタンをタップすると、これらのアニメーションをすべて停止することです。私はMKMapView Swift 3のすべてのアニメーションを停止します。iOS

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() 
    } 
} 

アニメーション/ピンの動きを作成するコードです。

+0

これは、iOS 10の「UIViewPropertyAnimator」を使用して行うことができます。これがうまくいくかどうかを確認するために、各UIViewのアニメーターを設定し、各アニメーターで '.startAnimation()'を呼び出してアニメーションを開始します。特定の 'UIView'のアニメーションを停止するには、適切なアニメーターの' .stopAnimation(true) 'を呼び出します。 –

+0

[UIViewブロックベースのアニメーションをキャンセルする方法]の複製がありますか?(http://stackoverflow.com/questions/9569943/how-to-cancel-uiview-block-based-animation) –

答えて

0

この問題を抱えている人は、問題は、アノテーションに関連付けられた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() 
関連する問題