简体   繁体   中英

showAnnotations when rotation changes

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?

Demo project

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM