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

前端 未结 1 734
醉酒成梦
醉酒成梦 2021-01-03 17:07

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

相关标签:
1条回答
  • 2021-01-03 17:25

    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)))
        }              
    }
    
    0 讨论(0)
提交回复
热议问题