UIWindow subviews do not autorotate

情到浓时终转凉″ 提交于 2020-02-04 07:46:48

问题


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];

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; }

What am I doing wrong?


回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/6929836/uiwindow-subviews-do-not-autorotate

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!