Please help out a beginner iOS developer here! :) So, I have a timer which gets the latitude and longitude of a bus periodically from a xml sheet which provides real-time lo
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)))
}
}