Michael
Michael

Reputation: 1009

UiSplitViewController doesn't autorotate

I have recently run into a problem. My iPad app is somehow preventing the iPad from auto-rotating. My app loads a UISplitView with both of the view controllers returning YES for shouldAutorotateToInterfaceOrientation:. I have set up my info.plist to include the "Supported interface orientations" key with all four orientations. When I run the app, however, rotating the device does not rotate the splitView (even though I am receiving UIDeviceOrientationDidChangeNotification). In addition, when I exit my app in a different orientation that it started in the iPad home screen doesn't autorotate to the correct view until I rotate it again without my app running.... Any Ideas would be much appreciated....

Upvotes: 6

Views: 6574

Answers (6)

Pascal Klein
Pascal Klein

Reputation: 24853

You said that your first Problem is, that the UISplitView prevents you from autorotating. Try to use a Subclass of Splitview instead that enbales autorotating:

@implementation SplitViewControllerRotating
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    NSLog(@"SplitViewControllerRotating shouldAutorotate");
    return YES;
}
@end

Your second problem sounds weird. You said after exiting your app you have to rotate, so that your iPad recognizes interface-orientation. Cant help you with that.

Upvotes: 0

Dirk-Willem van Gulik
Dirk-Willem van Gulik

Reputation: 7706

I found this to work fine - provided BOTH children of the UISplitViewController implement the shouldAutorotateToInterfaceOrientation:

I.e if you have something like:

        MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController_iPad" bundle:nil];
        UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];

        DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController_iPad" bundle:nil];
        UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];

        self.splitViewController.viewControllers = @[masterNavigationController, detailNavigationController];

       self.window.rootViewController = self.splitViewController;

to define the rootViewController of your NSApplication then both MasterViewController and DetailViewController should implement:

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return YES;
}

as to ensure that rotation works.

Upvotes: 2

wbdarby
wbdarby

Reputation: 1149

I ran into this same problem with two subordinate UINavigationControllers. In my case the rotation started working once I overrode shouldAutorotateToInterfaceOrientation: in the left controller to always return 'YES'.

Upvotes: 5

CIFilter
CIFilter

Reputation: 8677

UISplitViewController is one of the most temperamental view controller subclasses I've ever had to use. In order for it to work "perfectly", it must exist as a single root view in your application's window. You can, however, get around this with some trickery -- in my case, I needed a UITabBarController with at least two distinct UISplitViewControllers as view controllers -- but then you have to take care of weird cases involving rotation and UISplitViewControllerDelegate callbacks not firing.

Here's hoping that Apple makes UISplitViewController more compatible with other UIKit components in the future...

Upvotes: 8

Erik Asmussen
Erik Asmussen

Reputation: 231

Is your UISplitViewController set as your root view controller? If not, that may be the cause of your problem. I was having a similar issue - the status bar would rotate but my detail and master views would stay in place. I rearranged the views so that the UISplitViewController was the root and then my 'main menu' was presented as a modal view controller on top of the split view, and it made the rotation problem go away.

According to the iPad Programming Guide, "The split view controller’s view should always be installed as the root view of your application window."

Hope this helps.

Upvotes: 1

nschum
nschum

Reputation: 15422

I had the same problem right now. The reason was that I had accidentally added another view to the window in addition to UISplitViewController's view. Removing the extra view made it work.

Upvotes: 0

Related Questions