【发布时间】:2018-01-18 23:03:46
【问题描述】:
我正在创建类似于此处讨论的 Apple Maps 底页的内容: How to mimic iOS 10 maps bottom sheet
我创建了一个子视图infoViewController.xib (InfoViewController.swift - 代码和 InfoViewController.xib - 视图设计) 这个子视图将出现在我的地图前面,就像 Apple Maps 示例一样,因此您仍然可以看到它后面的地图。
mapView 由 MapViewController.swift 控制,我使用以下代码从那里调用它:
func addInfoView() {
let infoVC = InfoViewController()
self.addChildViewController(infoVC)
self.view.addSubview(infoVC.view)
infoVC.didMove(toParentViewController: self)
}
我在这个视图上设置了一个“方向”按钮作为 IBAction。当按下此按钮时,我希望它创建方向并将它们显示在 MapViewController 的地图上。目的地和当前位置信息通过 UserDefaults 传递给 infoViewController。我让它'工作':
@IBAction func infoDirectionButton(_ sender: Any) {
/*here i have it getting current and destination locations*/
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let mapViewController = storyboard.instantiateViewController(withIdentifier: "MapViewController") as! MapViewController
self.present(mapViewController, animated: false)
//routeDirection Method is in MapViewController and handles the direction requests
mapViewController.routeDirections(current: current, destination: destination)
mapViewController.addInfoView()
}
这会导致屏幕上显示方向,但不会在屏幕闪烁之前显示,因为它会重新加载我的 mapView 和 infoView(子视图)。
有没有办法让它在不重新加载父视图和子视图的情况下显示方向。
需要'self.present'代码,所以我可以在那个ViewController中调用该方法,它也不会在地图上显示方向。
self.present(mapViewController, animated: false)
和 addInfoView() 在显示路线后重新加载子视图。否则不再显示
mapViewController.addInfoView()
抱歉,如果这很难理解,我已尝试简化代码以突出问题。
【问题讨论】:
标签: ios swift mapkit parent-child swift4