开发者

How to handle rotation for a UIViewController that isnt on top of UINavigationController stack?

开发者 https://www.devze.com 2023-02-19 10:23 出处:网络
I have a root UIViewController (VC1), inside a UINavigationController, which handles rotation by adjusting its views/subviews frames manually in the willRotateToInterfaceOrientation: method. The rotat

I have a root UIViewController (VC1), inside a UINavigationController, which handles rotation by adjusting its views/subviews frames manually in the willRotateToInterfaceOrientation: method. The rotation works fine if the root UIViewController is the active view controller, basically on top of the stack.

The problem occurs when i push another UIViewController (VC2) onto the NavigationController. I then rotate VC2 which works fine. However when i pop VC2 the problem is t开发者_运维问答hat VC1 has not rotated to the correct orientation, nor does its willRotateToInterfaceOrientation: method get called?? The shouldAutorotateToInterfaceOrientation: method in VC1 is called but thats it.

My question then is how am i supposed to make sure that my UIViewController VC1 has been updated for the current orientation for this type of situation??


The way I resolve this is to check on viewWillAppear: to see if the orientation is now different to when viewDidDisappear was called. If so I call the code to layout the view.

To adopt this approach first factor the code responsible for laying out the view into something like _layoutViews, can simply call it as required in viewWillAppear as well as in willRotateToInterfaceOrientation:.

0

精彩评论

暂无评论...
验证码 换一张
取 消