根ViewController中的UIViewController不旋转 [英] UIViewController inside a root ViewController not rotating

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

问题描述

我有一个UIViewController,我想将其作为独立的图层添加到整个应用程序的顶部.因此,我尝试使用应用程序委托中的[self.window addSubview:viewController.view]将其添加到UIWindow中.

I have a UIViewController that I want to add on top of the entire app as an independent layer. So I tried adding it to the UIWindow using [self.window addSubview:viewController.view] in the app delegate.

但是,当用户旋转设备时,我的视图控制器中没有得到willRotateToInterfaceOrientation事件.因此,我尝试了此处提出的建议:我添加了视图控制器作为应用程序委托中窗口的根视图控制器的子视图,但仍未调用我的willRotateToInterfaceOrientation.

However, when the user rotates the device, I do not get the willRotateToInterfaceOrientation event in my view controller. So I tried doing what was suggested here: I added my view controller as a subview of the root view controller of the window in the app delegate, but my willRotateToInterfaceOrientation is still not being called.

我该怎么办?

推荐答案

您的rootViewController充当容器视图控制器.

Your rootViewController is acting as a container view controller.

在iOS 5.0和更高版本中,自定义UIViewController子类现在可以充当容器视图控制器.UINavigationController和UITabBarController类是UIKit提供的容器视图控制器的示例.容器视图控制器背后的想法是,它通过其包含的视图控制器(也称为其子视图控制器)管理内容的呈现.子内容可以按原样显示,也可以与容器视图控制器管理的其他其他自定义视图结合显示.

In iOS 5.0 and later, custom UIViewController subclasses can now act as container view controllers. The UINavigationController and UITabBarController classes are examples of container view controllers provided by UIKit. The idea behind a container view controller is that it manages the presentation of the content from its contained view controllers, also known as its child view controllers. The child content can be presented as-is or in conjunction with other other custom views managed by the container view controller.

您正在执行的是实现自己的视图层次结构,因此您有责任沿着该层次结构向下传递UILifecycle-Events.iOS> = 5.0支持您创建此类容器viewControllers,并提供

What you are doing is implementing an own view hierarchy, so you are responsible for passing the UILifecycle-Events down along that hierarchy. iOS >= 5.0 supports you creating such container viewControllers, offering the

- (void)addChildViewController:(UIViewController *)childController
- (BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers

方法(以及更多).对于iOS<5.0,您将不得不手动执行此操作.

methods (and more). For iOS < 5.0 you will unfortunately have to do this manually.

这篇关于根ViewController中的UIViewController不旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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