如何处理不在 UINavigationController 堆栈顶部的 UIViewController 的旋转?
我在 UINavigationController 中有一个根 UIViewController (VC1),它通过在 willRotateToInterfaceOrientation: 方法中手动调整其视图/子视图框架来处理旋转。如果根 UIViewController 是活动视图控制器(基本上位于堆栈顶部),则旋转效果很好。
当我将另一个 UIViewController (VC2) 推到 NavigationController 上时,就会出现问题。然后我旋转 VC2,效果很好。然而,当我弹出 VC2 时,问题是 VC1 没有旋转到正确的方向,也没有调用它的 willRotateToInterfaceOrientation: 方法?调用了VC1中的shouldAutorotateToInterfaceOrientation:方法,仅此而已。
那么我的问题是我应该如何确保我的 UIViewController VC1 已针对此类情况的当前方向进行更新?
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 that 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??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我解决此问题的方法是检查
viewWillAppear:
以查看现在的方向是否与调用viewDidDisappear
时不同。如果是这样,我调用代码来布局视图。要采用这种方法,首先将负责将视图布局为
_layoutViews
的代码考虑在内,可以根据viewWillAppear
以及willRotateToInterfaceOrientation 中的要求简单地调用它:
。The way I resolve this is to check on
viewWillAppear:
to see if the orientation is now different to whenviewDidDisappear
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 inviewWillAppear
as well as inwillRotateToInterfaceOrientation:
.