gpt4 book ai didi

ios - willRotateToInterfaceOrientation 如果不可见则不会被调用

转载 作者:行者123 更新时间:2023-12-01 18:59:57 25 4
gpt4 key购买 nike

我有以下结构(iOS 7 应用程序):
UIWindow -> UITabBarController -> 2 个标签
表 1:NavigationControllerHomeViewController作为根。
表 2:NavigationControllerOtherViewController作为根。

如果我在 Tab1 中旋转 iPad,HomeViewController执行 WillRotateToInterfaceOrientation:没有问题。但如果我在 Tab2 并旋转 iPad,willRotate: HomeViewController的方法在 Tab1 中不执行,所以当我回到 Tab1 时, View 的布局方向错误并且搞砸了。

发生了什么?提前感谢您的知识。

最佳答案

这是 iOS 上的预期行为,因为 HomeViewController设备旋转时未显示。

查看 Apple documentation用于支持多个 View Controller 界面方向。

具体来说, 部分隐藏 View Controller 时可能会发生旋转 ,内容如下:

If your view controller’s contents are not onscreen when a rotation occurs, then it does not see the list of rotation messages. For example, consider the following sequence of events:

Your view controller presents another view controller’s contents full screen. The user rotates the device so that the user interface orientation changes. Your app dismisses the presented view controller. In this example, the presenting view controller was not visible when the rotation occurred, so it does not receive any rotation events. Instead, when it reappears, its views are simply resized and positioned using the normal view layout process. If your layout code needs to know the current orientation of the device, it can read the app object’s statusBarOrientation property to determine the current orientation.



所以基本上你必须准备好你的 View Controller ,以便根据它没有收听通知时可能发生的旋转来更新自己。

最常见的方法是在 viewWillAppear: 上放置特定于接口(interface)的代码。 ,因为每次您的 View Controller 显示在屏幕上时都会调用此方法。

关于ios - willRotateToInterfaceOrientation 如果不可见则不会被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23500263/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com