UIWindow子视图不会自动旋转 [英] UIWindow subviews do not autorotate

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

问题描述

我要离开拆分视图控制器,以便并排获得两个垂直表视图,就像设置应用程序一样.在我的iPad AppDelegate中,我写了以下代码:

I am switching away from a split view controller in order to get two vertical table views side by side, just like the settings app. In my iPad AppDelegate I write the following code :

rootViewController.view.frame = CGRectMake(0, 20, 270, 1004);
[window addSubview:rootViewController.view];

detailViewController.view.frame = CGRectMake(270,20, 498, 1004);
[window addSubview:detailViewController.view];

[window makeKeyAndVisible];

这非常有用,它可以使所有内容按原样显示在肖像中.但是,当我旋转设备时,我的rootViewController会旋转,而详细视图控制器不会.在我的两个控制器中,我都在实现

This works great to get everything to show up in portrait just as it should. However when I rotate the device my rootViewController rotates, and the detail view controller does not. In both of my controllers I am implementing

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; }

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; }

我在做什么错了?

推荐答案

这是预期的行为. UIWindow中只有第一个"视图的旋转将由窗口管理.有关详细信息,请参见技术问答A QA1688 .

This is expected behavior. Only the "first" view in the UIWindow will have its rotation managed by the window. See Technical Q&A QA1688 for details.

如果您不打算使用UISplitViewController,那么下一个最好的选择就是消除根视图和局部视图控制器,并从一个父级UIViewController管理视图.

If you're not going to use UISplitViewController, the next best thing would be to eliminate your root and detail view controllers and manage the views from one parent UIViewController.

如果您不想这样做,可以尝试将rootViewController.viewdetailViewController.view作为子视图添加到一个顶级UIViewController中,但是请记住,您将必须管理所有将出现的/将会出现的/disappear和rotation方法需要您自己调用子控制器,并且某些事情会中断,因为子控制器的parentViewController为零,而不是您的顶级控制器.

And if you don't want to do that, you could try adding rootViewController.view and detailViewController.view as subviews inside one top-level UIViewController, but keep in mind that you will have to manage all the will/did appear/disappear and rotation method calls for the sub-controllers yourself, and some things will break because the subcontrollers' parentViewController will be nil rather than your top-level controller.

这篇关于UIWindow子视图不会自动旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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