我正在研究这个我没有找到任何文档,所以我想我会创建一些。在我解决它之后,我就像哦,这比我想象的要容易。
无论如何,我想创建我在苹果地图上看到的 3 个按钮状态。我尝试了一些 setRegion 的东西。经过一些工作后,才意识到苹果打算如何使用它。所以我想我会在这里记录下来。
我正在研究这个我没有找到任何文档,所以我想我会创建一些。在我解决它之后,我就像哦,这比我想象的要容易。
无论如何,我想创建我在苹果地图上看到的 3 个按钮状态。我尝试了一些 setRegion 的东西。经过一些工作后,才意识到苹果打算如何使用它。所以我想我会在这里记录下来。
func locationButtonWasPressed() {
switch self.coreMapView.userTrackingMode {
case .none:
self.coreMapView.userTrackingMode = .follow
case .follow:
self.coreMapView.userTrackingMode = .followWithHeading
case .followWithHeading:
self.coreMapView.userTrackingMode = .none
@unknown default:
print("userTrackingMode undefined")
}
}
func mapView(_ mapView: MKMapView, didChange mode: MKUserTrackingMode, animated: Bool) {
switch mode {
case .none:
let tintedImage = #imageLiteral(resourceName: "nearby").withRenderingMode(.alwaysTemplate)
locationButton.image = tintedImage
case .follow:
let tintedImage = #imageLiteral(resourceName: "nearby-selected").withRenderingMode(.alwaysTemplate)
locationButton.image = tintedImage
case .followWithHeading:
let tintedImage = #imageLiteral(resourceName: "scout").withRenderingMode(.alwaysTemplate)
locationButton.image = tintedImage
@unknown default:
print("userTrackingMode undefined")
}
}