Swift mapkit 如何隐藏用户的位置图钉

Swift mapkit how to hide user's location pin

我找不到任何相关文档,所以也许我无论如何也问不出来。我需要显示用户位置的蓝点。我的地图视图充满了图钉,有时我的用户点击用户位置的蓝色圆圈,这会打开一个小的用户图片图钉。我怎样才能删除它?后面有东西就烦了

到目前为止,我必须像这样打开注释视图时进行识别:

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
    if(view.annotation?.isKind(of: MKUserLocation.self) != true){
        print("test");
    }
}

有没有办法取消显示?

您已完成 99% 的解决方案 - 您已确定何时选择了用户位置注释。您只需取消选择即可完成任务;

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
        
    if view.annotation is MKUserLocation {
        mapView.deselectAnnotation(view.annotation, animated: false)
        return
    }

    // Handle selection of other annotations if required...
}