[英]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.