I am creating something similar to Apple Maps' bottom sheet which is discussed here: How to mimic iOS 10 maps bottom sheet
I worked through creating a child view infoViewController.xib (InfoViewController.swift - code and InfoViewController.xib - design of view) This Child view will appear in front of my map just like the Apple Maps example so you can still see the map behind it.
The mapView is controlled by MapViewController.swift, I use the following code to call it from there:
func addInfoView() {
let infoVC = InfoViewController()
self.addChildViewController(infoVC)
self.view.addSubview(infoVC.view)
infoVC.didMove(toParentViewController: self)
}
I set up a 'directions' button on this view as an IBAction. When this button is pressed I want it to create directions and display them on the map in MapViewController. The destination and current location information is passed via UserDefaults to infoViewController. I have it 'working':
@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()
}
This results in the directions being shown on the screen, however not before the screen flashing as it reloads my mapView and the infoView (child view).
Is there a way I can get it to display the directions without reloading both the parent view and child view.
the 'self.present' code is needed so I can call the method in that ViewController, it also wont display the directions on the map either.
self.present(mapViewController, animated: false)
and addInfoView() to reload the child view after the directions have been displayed. Otherwise it is not shown again
mapViewController.addInfoView()
Apologies if this is hard to follow, I have tried to simplify the code to highlight the issue.