I have a SplitViewController
with a mapview on as the detailViewController.
I add multiple annotations to the mapview. After adding them I call the showAnnotations:animated:
method to zoom in/out the map so that all the annotations are shown in the visible portion of the map.
mapView.showAnnotations(mapView.annotations, animated: true)
Now I need the map to refocus itself when the orientation changes because the mapview's visible area reduces when you turn the iPad to portrait. So I call the same showAnnotations:animated:
method in viewWillTransitionToSize:withTransitionCoordinator:
method which fires when the orientation changes. But it doesn't work as expected.
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
mapView.showAnnotations(mapView.annotations, animated: true)
}
How do I make it refocus when orientation changes?
Calling the showAnnotations
within the viewDidLayoutSubviews
method works perfectly.
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
mapView.showAnnotations(mapView.annotations, animated: true)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.