UIViewController 旋转方法 [英] UIViewController rotate methods
问题描述
哪个对象负责分配 UIViewController
旋转方法调用,即:
What object is responsible for dipatching the UIViewController
rotation method calls, i.e:
shouldAutorotateToInterfaceOrientation:
willRotateToInterfaceOrientation:duration:
willAnimateFirstHalfOfRotationToInterfaceOrientation:duration:
willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:
didRotateFromInterfaceOrientation:
我想它是 UIApplication
(但可能是 AppDelegate 或 UIWindow).
I imagine it is UIApplication
(but maybe the AppDelegate or UIWindow).
下一个问题,对象如何知道要与哪个 UIViewController
对话?
The next question, is how does the object know which UIViewController
to talk to?
它如何知道哪个 UIViewController
将其视图作为窗口的子视图?
How does it know which UIViewController
has its view as the subview of the window?
是否有您可以发送的消息或您可以设置的(某些对象的)属性来设置应用程序的活动"UIViewController
?
Is there a message you can send or a property you can set (of some object) that sets the "Active" UIViewController
for the app?
推荐答案
看来 UIApplication
正在向活动视图控制器分派消息.
It seems that UIApplication
is dispatching a message to the active view controller.
但是您的 View Controller 实例如何获取这些消息?
But how does your View Controller instance get these messages?
消息被转发到第一个视图控制器,其视图已添加到 UIWindow
实例.
The message is forwarded to the first view controller whose view has been added to the UIWindow
instance.
这归结为 3 个基本场景:
This boils down to 3 basic scenarios:
视图所在的ViewController直接添加到
UIWindow
实例(单视图应用)
导航控制器基于导航的应用程序,然后导航控制器转发消息到活动视图视图控制器.
The navigation Controller in a Navigation based app, then the navigation controller forwards the message to the active views view controller.
标签栏中的标签栏控制器基于应用程序,然后是标签栏控制器将消息转发到活动视图视图控制器(或活动导航控制器).
The tab bar Controller in a tab bar based app, then the tab bar controller forwards the message to the active views view controller (or the active navigation controller).
您将遇到的问题是,如果您构建具有多个视图的应用程序,但不要使用导航控制器或标签栏控制器.如果您手动交换视图进出 UIWindow
实例,您将无法可靠地接收这些消息.这类似于这样的帖子:iPhone viewWillAppear 未触发
The problem you will have, is if you build an app with multiple views, but DO NOT use a Navigation controller or Tab Bar controller. If you swap views in and out of the UIWindow
instance manually, you will not receive these messages reliably.
This is similar to posts like this one:
iPhone viewWillAppear not firing
只需将 Apple 的约定用于多个视图,就可以了.希望这可以节省一两个小时的时间
Just use Apple's conventions for multiple views and you be fine. Hope this saves some one an hour or two
这篇关于UIViewController 旋转方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!