Animation 如何:iOS MapKit动画图像标记/注释
我有一系列的图像要用作动画,我想将此动画应用于特定的注释 如何更改MapKit默认注释图像以及如何将其设置为动画?要设置自定义图像或动画图像标记注释:Animation 如何:iOS MapKit动画图像标记/注释,animation,swift3,mapkit,sequence,mkannotation,Animation,Swift3,Mapkit,Sequence,Mkannotation,我有一系列的图像要用作动画,我想将此动画应用于特定的注释 如何更改MapKit默认注释图像以及如何将其设置为动画?要设置自定义图像或动画图像标记注释: 在参考资料中:将所需的动画X序列图像:frame_1.png添加到frame_X.png 在代码中:使用MKMapViewDelegte扩展视图控制器,如下所示: class MyViewController:MKMapViewDelegate 在故事板中: 选择地图套件视图 转到实用程序框架并选择 连接检查员 将委托元素与 控制器 现在,您
- 在参考资料中:将所需的动画X序列图像:frame_1.png添加到frame_X.png
- 在代码中:使用MKMapViewDelegte扩展视图控制器,如下所示:
class MyViewController:MKMapViewDelegate
在故事板中:
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
}
}
如果不需要动画,只需从代码中删除计时器行