Auto rotating ipad sub views
I have a large application that I am working on which has a primary view, call it a root view, with toolbar at the top for program control. There are a number of additional views that overlay the "root" view but leaving the toolbar visible - There is a popover menu that controls which sub view is show over the "root" view. Please note, I am not using a splitview controller.
To save resources I initialize the different sub views when their function is selected from the menu the first time. All the sub views have been designed in IB. When the ipad is in portrait mode when the submenus are first select all the auto rotation works just fine, however when the ipad is in a landscape orientation when the application is first started and the subviews are first launched, they are not rotated and shown in a clipped portrait mode. They don't appear to know that the iPad is rotated.
If I initialize all the sub views from the "root" viewDidLoad method, they they all rotate properly regardless of what orientation the ipad is when it is started. So if I initialize the subviews before the "root" view is visible, then all is well. If I initialized them after the "root" view becomes visible, the sub views don't appear to auto rotate.
A开发者_如何学JAVAs there is a lot of code involved, I hope I have explained this clear enough so someone with a more experience or insight might put me on the right track.
Thanks Jim
Jim, When adding subviews to your main UIWindow, a change in the order in which you add them can affect how these views are affected by the initial orientation of the device. For example, in an App with a navigation controller (created in code) and a view controller (created in IB), the following code will display correctly regardless of the initial orientation:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[self.window addSubview:navigationController.view];
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
However, the following piece of code will be messed up when the app is started in landscape mode (note the order of the addSubview calls in window):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[self.window addSubview:viewController.view];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
I'd try changing the order in which you add the subviews. Hope this helps!
精彩评论