【发布时间】:2019-06-20 20:43:31
【问题描述】:
我希望将用户位置显示为自定义图像(而不是蓝色信标)。我还希望每当用户位置更改其坐标时,此自定义图像都会相应地旋转以表示用户路线。为了实现这一点,我实现了下面的代码。当应用程序启动时,它使用注释类型 userLocation 调用,以便用户位置自定义图像显示正常。问题是,当我模拟用户位置坐标的变化时,委托 mapView(_:viewFor:) 方法永远不会使用注释类型 userLocation 再次调用,因此图像永远不会旋转。 (注意:UIImage rotateImage(by:) 是自定义方法)。
是否有一些方法可以调用 mapView(_:viewFor:) 以便在用户位置更改时更新用户位置的图像注释?感谢您的帮助。
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation.isEqual(mapView.userLocation) {
// Annotation image for user location
let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: nil)
annotationView.image = UIImage(named: "UserLocationImage.png")?.rotateImage(by: currentCourse)
return annotationView
}
}
【问题讨论】:
标签: swift annotations mapkit core-location