UiSplitViewController doesn't autorotate

前端 未结 6 2124
小蘑菇
小蘑菇 2020-12-15 13:02

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 Y

相关标签:
6条回答
  • 2020-12-15 13:39

    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.

    0 讨论(0)
  • 2020-12-15 13:44

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

    0 讨论(0)
  • 2020-12-15 13:46

    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.

    0 讨论(0)
  • 2020-12-15 13:49

    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.

    0 讨论(0)
  • 2020-12-15 13:53

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

    0 讨论(0)
  • 2020-12-15 14:01

    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.

    0 讨论(0)
提交回复
热议问题