iosuinavigationcontrollerautorotaterootviewcontrollershouldautorotate

iOS with NavigationController As Root Make, One Controller ONLY Landscape


I have an app in which the root controller is a UINavigationController. Push one button, and it pushes another view controller. Push yet another and it starts an AVCaptureSession with Overlay. I want THAT view, and that view ONLY to be Landscape, and not portrait. I have looked at a ton of different tutorials, and nothing is working.

The closest I have gotten is:

NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];

in the viewDidAppear. However, there are some issues. One, it immediately goes right back to Portrait. Two, the other views are still all able to be portrait and landscape and I don't want that. I need help, please.


Solution

  • In my app delegate, I use this code and make sure only portrait mode is selected:

    - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
    {
        if ([self.window.rootViewController.presentedViewController isKindOfClass:[SecondViewController class]])
        {
            SecondViewController *secondController = (SecondViewController *) self.window.rootViewController.presentedViewController;
    
            if (secondController.isPresented)
            {
                return UIInterfaceOrientationMaskLandscape;
            }
            else return UIInterfaceOrientationMaskPortrait;
        }
        else return UIInterfaceOrientationMaskPortrait;
    }