Ios 如何在不更改Swift中默认位置pin的情况下更改MapKit中的markerTintColor?
我有MkMarkerNotationView来更改地图上图钉的颜色Ios 如何在不更改Swift中默认位置pin的情况下更改MapKit中的markerTintColor?,ios,swift,annotations,mapkit,swift4,Ios,Swift,Annotations,Mapkit,Swift4,我有MkMarkerNotationView来更改地图上图钉的颜色 func mapView(_ MapView:MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?{ let view = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "pin") view.markerTintColor = .blue
func mapView(_ MapView:MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?{
let view = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "pin")
view.markerTintColor = .blue
return view
}
但是,当我启动我的应用程序时,我的defoult位置标记变为。
如何在不更改此标记的情况下更改pin?
查看位置的代码也很简单
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
self.MapView.showsUserLocation = true
}
谢谢你的回答!:) 在方法中,检查注释对象是否是
MKUserLocation
的实例。如果是,则返回nil以保留标准用户位置注释视图
(用于
mapView(uuquo;viewFor:)
的文档对此进行了解释。)在您的方法中,检查注释对象是否是MKUserLocation
的实例。如果是,则返回nil以保留标准用户位置注释视图
(用于
mapView(u:viewFor:)
的文档对此进行了解释。)您可以检查注释是否为如下所示的用户位置:
func mapView(_ MapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
let view = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "pin")
view.markerTintColor = .blue
return view
}
您可以检查注释是否为如下所示的用户位置:
func mapView(_ MapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
let view = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "pin")
view.markerTintColor = .blue
return view
}