地图旋转时,我的代码确实旋转annotationViewImage
。
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "mark")
annotationView.image = UIImage(named: "pinArrow")
let ang = mapView.camera.heading
let radi = Double.pi * Double(ang / 360)
let resultAng = 2 * Float(radi)
annotationView.transform = CGAffineTransform(rotationAngle: CGFloat(-resultAng))
annotationView.canShowCallout = true
return annotationView
}
以上代码,当地图旋转时,不实现上述方法。 因此,添加以下代码
func mapViewDidChangeVisibleRegion(_ mapView: MKMapView) {
print("visible")
let anns = mapView.annotations
mapView.removeAnnotations(anns)
mapView.addAnnotations(anns)
}
,然后,当地图旋转时,annotationView
图像也会旋转。
但是这么慢一些,而加载时间又长一些。
因为上面代码的地图移动委托,所以很多重复。
我寻求一种更简单的方法,而不会缓慢加载。
如何旋转同步地图和annotationView
图片?