【问题标题】:Swift 4 mapkit reloads map after hiding map annotationsSwift 4 mapkit 在隐藏地图注释后重新加载地图
【发布时间】:2018-04-29 21:13:55
【问题描述】:

我有两个视图控制器,它们显示一个 mapkit,一个用于具有后退按钮的地点描述。但是每次我尝试隐藏地图注释并转到地点描述然后再次返回到 mapkit 时,它都会使用我尝试隐藏的注释重新加载我的地​​图。如何防止 mapkit 重新加载其数据但仍隐藏我的地图注释?

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
        //1
        let coordinate = view.annotation!.coordinate
        //2
        if let userCoordinate = userLocation {
            //3
            if userCoordinate.distance(from: CLLocation(latitude: coordinate.latitude, longitude: coordinate.longitude)) < 30000 {
                //4

                let storyboard = UIStoryboard(name: "Main", bundle: nil)

                if let viewController = storyboard.instantiateViewController(withIdentifier: "ARViewController") as?    PlaceViewController {
                    // more code later
                    //5
                    if let mapAnnotation = view.annotation as? MapA {
                        //6
                        if(mapAnnotation.title == "New")
                        {
                         mapView.view(for: mapAnnotation)?.isHidden = true
                            self.present(viewController, animated: true, completion: nil)
                            viewController.adL.text = "TEST"
                       viewController.descT.text = "Hej"



                        }
}

【问题讨论】:

    标签: swift annotations mapkit


    【解决方案1】:

    因为这里会重新加载

    mapView.view(for: mapAnnotation)?.isHidden = true
    

    你明确调用它来重新加载

    你可以直接做

    view.isHidden = true 
    

    当你看到这里的景色

    didSelect view: MKAnnotationView
    

    当前选中的

    【讨论】:

    • 我已更改为 view.isHidden = true,但在我按下后它仍在重新加载我的地​​图。
    • viewDidAppear 或 viewWillAppear 里面有代码吗?
    • 不,只有 viewDidLoad 中的代码位于 viewcontroller 中。但在我展示我的视图控制器之前,我看到我的地图注释是隐藏的,直到我按下返回按钮。
    • 我也试过 selectedAnnotation = view.annotation mapView.removeAnnotation(selectedAnnotation!) 但仍然是同样的错误。还有其他建议吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多