ios - Swift 3.0 map 返回到以前的 MapView

标签 ios swift dictionary mkmapview

我有一个带有注释的 mapView,当单击它时,它会移动到一个新的 viewController。然后,当用户选择从详细信息披露返回到 mapView 时,我希望 mapView 具有与用户在单击详细信息披露之前相同的 View 。以下是我到目前为止设置的代码,但是,当用户从详细信息披露中单击返回时, map 会缩小。我不确定如何重新创建以前的 View 。

详细披露 VC:

// here by segueing, I want to communicate to the MapView VC that the map should remain the same  
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if (segue.identifier == "backButtonTapped" )
    {
        let destinationVC = segue.destination as! TabBarVC
        mapStatus = "wentBack"
        print("The value of mapStatus after seguing is \(mapStatus)")
        destinationVC.selectedIndex = 1

    }

}

map View VC:

 override func viewDidAppear(_ animated: Bool) {
    // here if the mapStatus is not the correct value (the user never used the detail disclosure), the map will just snap onto the current location

    if mapStatus == "wentBack" {
       print("Do not update location")

       // assuming appropriate code is placed here but I am not sure what it is


    } else {
        print("Updated Current Location")
    let center = CLLocationCoordinate2D(latitude: self.lastLocation.coordinate.latitude, longitude: self.lastLocation.coordinate.longitude)
    let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))

    map.setRegion(region, animated: true)

        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        if #available(iOS 8.0, *) {
            locationManager.requestAlwaysAuthorization()
        } else {
            // Fallback on earlier versions
        }
        let noLocation = CLLocationCoordinate2D()
        let viewRegion = MKCoordinateRegionMakeWithDistance(noLocation, 200, 200)
        map.setRegion(viewRegion, animated: false)

    }
    }

最佳答案

事实证明, map 不会持续存在,因为当用户返回详细信息披露时调用 viewDidLoad(使用 prepareForSegue)。我用过

@IBAction func backButtonTapped(_ sender: UIBarButtonItem) {
    self.dismiss(animated: true)
    mapStatus = "wentBack"

} 

为了关闭 viewController,只调用 viewDidAppear 而不是 viewDidLoad。

关于ios - Swift 3.0 map 返回到以前的 MapView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44894949/

相关文章:

java - 在迭代 hashmap 时执行循环展开

ios - 不使用 Storyboard 的应用程序状态保存和恢复?

ios - 用超能力播放 ipod 库中的歌曲

ios - 苹果AppStore更新进程: how it affects the existing files

objective-c - 在ios中进行持续方法更新的有效方法

ios - 我的 Sprites 在 Sprite Kit 中使用 Swift 被压缩

python - 长格式 Pandas 数据框到字典

swift - 饼图不可拖动

swift - 客户没有带 ID 的链接源

dictionary - 将 "not"添加到 Clojure 序列中的每个项目