UIViewController旋转方法 [英] UIViewController rotate methods

查看:148
本文介绍了UIViewController旋转方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么对象负责完成 UIViewController 旋转方法调用,即:

What object is responsible for dipatching the UIViewController rotation method calls, i.e:


  • shouldAutorotateToInterfaceOrientation:

  • willRotateToInterfaceOrientation:duration:

  • willAnimateFirstHalfOfRotationToInterfaceOrientation:duration:

  • willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:

  • didRotateFromInterfaceOrientation:

  • 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?

是否有可以发送的消息或者您可以设置的属性(某些对象) a的Active UIViewController pp?

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:


  1. ViewController的视图是
    直接添加到 UIWindow
    实例(单一视图应用)

  1. The ViewController whose view is added directly to the UIWindow instance (single view app)


基于导航的应用中的导航控制器,然后
导航控制器将
消息转发到活动视图视图
控制器。

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).

您将遇到的问题是,如果您构建具有多个视图的应用程序,但请勿使用导航控制器或Tab Bar控制器。如果您手动交换视图进出 UIWindow 实例,则不会可靠地接收这些消息。
这类似于这样的帖子:
iPhone viewWillAppear not firing

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆