How do I force a specific UIInterfaceOrientation on an individual view in a UINavigationController?

后端 未结 8 887
闹比i
闹比i 2020-12-14 17:27

Okay, so here\'s the situation:

I have an app in which I only want ONE specific view in a UINavigationController to have a landscape orientation. This view is a UIIm

8条回答
  •  粉色の甜心
    2020-12-14 18:21

    The UINavigationController overrides the contain UIViewController orientation settings, so you have to create a custom subclass of UINavigationController with the following for 5.1:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        if ([[self topViewController] isKindOfClass:[SigCaptureViewController class]]) {
            return UIInterfaceOrientationIsLandscape(interfaceOrientation);
        } else {
            return UIInterfaceOrientationIsPortrait(interfaceOrientation);
        }
    }
    

    For 6.0 and above you need:

    - (BOOL)shouldAutorotate
    {
        return YES;
    }
    
    - (NSUInteger)supportedInterfaceOrientations {
        if ([[self topViewController] isKindOfClass:[EXTRASigCaptureViewController class]]) {
            return UIInterfaceOrientationMaskLandscape;
        } else {
            return UIInterfaceOrientationMaskPortrait;
        }
    }
    

    What I haven't figured out is how to make the force the UINavigationController to rotate. calling [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO] causes the status bar to rotate but doesn't cause the view to rotate.

提交回复
热议问题