Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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....

like image 786
Michael Avatar asked Apr 29 '10 00:04

Michael


3 Answers

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...

like image 70
CIFilter Avatar answered Oct 11 '22 14:10

CIFilter


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'.

like image 39
wbdarby Avatar answered Oct 11 '22 13:10

wbdarby


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.

like image 30
Dirk-Willem van Gulik Avatar answered Oct 11 '22 13:10

Dirk-Willem van Gulik