I have a split view app running fine on the iPad. It is using the default setup (Popover in Portrait, table view开发者_如何学Go on the left in landscape). The views shift correctly once the app is running. The problem I am seeing is that when the app starts (in the simulator) running in landscape mode the UI paradigm is the one intended for Portrait mode (Master List is a popover) is what loads.
I am thinking this is some strangeness with the simulator, or I am missing an option on my main view controller.
I ran into the same problem as is described here. The solution was, embarrassingly, as simple as manually setting the view's frame before adding it to the window.
Just check the interface orientation and, if it's landscape, switch the application frame width and height dimensions (i.e., width becomes height, height becomes width).
CGRect frame = [[UIScreen mainScreen] applicationFrame];
switch(controller.interfaceOrientation){
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
[controller.view setFrame:frame];
break;
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
[controller.view setFrame:CGRectMake(frame.origin.x, frame.origin.y, frame.size.height, frame.size.width)];
break;
}
Adding this as an answer as well in the hopes it will be more apparent to those in need of the same fix.
I solved this. I was waiting for an external XML stream to be loaded & parsed. As a result I was loading the window with the splitViewController view AFTER my applicationDidFinishLaunching
method.
Adding:
[window addSubview: splitViewController.view];
[window makeKeyAndVisible];
back into that method fixed the orientation recognition
I succeeded into displaying a loading view by doing
[window addSubview:self._splitViewController.view];
[window addSubview:self._myLoadingView];
self._splitViewController.view.hidden = YES;
[window makeKeyAndVisible];
[self loadAllDatas];
self._splitViewController.view.hidden = NO;
i works fine
It doesn't work correctly because the default detail view controller of UISplitViewController is just a plain UIViewController. The shouldRotate method of UIViewController returns YES for portrait mode only.
Adding a generic UIViewController returning YES in shouldRotate for all orientations solved the problem for me.
精彩评论