首页 > 解决方案 > Swift 4 mapkit 在隐藏地图注释后重新加载地图

问题描述

我有两个视图控制器,它们显示一个 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"



                        }
}

标签: swiftannotationsmapkit

解决方案


它重新加载,因为这里

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

您明确调用它来重新加载

你可以直接做

view.isHidden = true 

当你看到这里的景色

didSelect view: MKAnnotationView

当前选择的


推荐阅读