UiSplitViewController doesn't autorotate

廉价感情. 提交于 2019-12-29 04:54:11

问题


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


回答1:


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




回答2:


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




回答3:


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.




回答4:


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.




回答5:


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.




回答6:


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.



来源:https://stackoverflow.com/questions/2734016/uisplitviewcontroller-doesnt-autorotate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!