UiSplitViewController doesn't autorotate
Asked Answered
G

6

6

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

Goldeneye answered 29/4, 2010 at 0:21 Comment(0)
H
8

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

Heldentenor answered 1/9, 2010 at 18:35 Comment(3)
You can get around it with trickery you say... What trickery? You tease!Pyonephritis
What it came down to was just forwarding appropriate rotation methods manually. Logging a bunch of stuff to see what methods were and we're not being called. Then I just compensated in my root view controller subclass by making sure the child view controllers got the right methods fired, resized their views, etc.Heldentenor
I am having the same problem right now of having my SplitViewController's, which are tabs under a TabBarController, act erratic, so it's glad to know it's not just me! Thanks for that comfort at least!Actinomorphic
S
5

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

Stereotype answered 25/2, 2011 at 7:21 Comment(1)
Both the masterView and the detailView need to support YES for whatever orientation you are trying to rotate to. If either one doesn't return YES, it won't rotate. I missed this subtle detail, my masterView only supported portrait. Hope this helps someone else.Divorcement
C
2

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.

Celibacy answered 5/6, 2013 at 7:13 Comment(0)
F
1

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.

Favored answered 25/6, 2010 at 16:16 Comment(0)
M
0

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.

Misplay answered 29/4, 2010 at 0:21 Comment(0)
L
0

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.

Legman answered 27/5, 2010 at 8:32 Comment(2)
I gave it a shot... It didn't work... Isn't the purpose of the UISplitView to autorotate anyway?Goldeneye
Does anyone know a solution on iOS 9? Answers answered above are deprecated.Wilonah

© 2022 - 2024 — McMap. All rights reserved.