ViewController中的UIViewController

ViewController中的UIViewController

本文介绍了根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.

您正在执行的是实现自己的视图层次结构,因此您有责任沿着该层次结构向下传递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不旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 01:54