【发布时间】:2017-06-18 09:48:31
【问题描述】:
我有一系列想用作动画的图像,我想将此动画应用于特定的注释。
如何更改 MapKit 默认注释图像以及如何使其动画化?
【问题讨论】:
标签: animation swift3 mapkit sequence mkannotation
我有一系列想用作动画的图像,我想将此动画应用于特定的注释。
如何更改 MapKit 默认注释图像以及如何使其动画化?
【问题讨论】:
标签: animation swift3 mapkit sequence mkannotation
制作自定义图像或动画图像标记注释:
class MyViewController: MKMapViewDelegate
在故事板中:
现在您的视图控制器可以从 MapView 获取回调。
在代码中: 添加以下代码以覆盖标记/注释设置回调
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?
{
if !(annotation is MKPointAnnotation) {
return nil
}
let reuseId = "test"
anView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId)
if anView == nil {
anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
anView!.image = UIImage(named:"frame_1")
anView!.canShowCallout = true
Timer.scheduledTimer(timeInterval: 0.05, target: self, selector: #selector(Changeimage), userInfo: nil, repeats: true)
}
else {
anView!.annotation = annotation
}
return anView
}
func Changeimage()
{
if count == 8
{
count=0
}
else
{
anView!.image = UIImage(named:"frame_\(count+1)")
anView!.canShowCallout = true
count=count+1
}
}
如果您不需要动画,只需从代码中删除 Timer 行。
【讨论】: