简体   繁体   English

旋转变化时的showAnnotations

[英]showAnnotations when rotation changes

I have a SplitViewController with a mapview on as the detailViewController. 我有一个带有mapview的SplitViewController作为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. 添加它们之后,我调用showAnnotations:animated:方法来放大/缩小地图,以便所有注释都显示在地图的可见部分。

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. 现在,当方向改变时,我需要地图重新聚焦,因为当您将iPad转到纵向时,地图视图的可见区域会减小。 So I call the same showAnnotations:animated: method in viewWillTransitionToSize:withTransitionCoordinator: method which fires when the orientation changes. 因此,我在viewWillTransitionToSize:withTransitionCoordinator:方法中调用了相同的showAnnotations:animated:方法,该方法会在方向更改时触发。 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. viewDidLayoutSubviews方法内调用showAnnotations效果很好。

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()

    mapView.showAnnotations(mapView.annotations, animated: true)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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