Custom annotation image rotates only at the beginning of the Program (Swift- iOS)

无人久伴 提交于 2019-11-30 16:29:00

The rotation only occurs the first time the map view creates the view for the annotation. Rather than create a new view every time an annotation updates, it simply moves the view. That's much more efficient for the map view to do. So, what you should do is make the pinView a property, instantiate it in your init method, return that in mapView(, viewForAnnotation:) and apply the rotation directly to that pinView in your animation block.

UIView.animateWithDuration(0.5) {
    self.busAnnotation.coordinate = CLLocationCoordinate2DMake(latitude!, longitude!)                  
    self.map.addAnnotation(self.busAnnotation)
    if let pv = self.pinView {
        pv.transform = CGAffineTransformRotate(self.map.transform, CGFloat(degreesToRadians(self.busDirection)))
    }              
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!