【问题标题】:Swift mapkit how to hide user's location pinSwift mapkit如何隐藏用户的定位销
【发布时间】:2021-12-06 16:52:59
【问题描述】:

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

到目前为止,当我像这样打开注释视图时,我必须确定:

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

有没有办法取消它的显示?

【问题讨论】:

    标签: ios swift mapkit mapkitannotation


    【解决方案1】:

    您已完成 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...
    }
    

    【讨论】:

    • 啊,我很接近,我确实直接返回,但我没有想到取消选择注释。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-01
    • 1970-01-01
    • 2020-06-28
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多