How to force view controller orientation in iOS 8?

前端 未结 25 2542
太阳男子
太阳男子 2020-11-22 13:11

Before iOS 8, we used below code in conjunction with supportedInterfaceOrientations and shouldAutoRotate delegate methods to force app orie

25条回答
  •  醉话见心
    2020-11-22 13:25

    I have tried many solutions, but the one that worked for is the following:

    There is no need to edit the info.plist in ios 8 and 9.

    - (BOOL) shouldAutorotate {
        return NO;
    }   
    
    - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
        return (UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown);
    }
    

    Possible orientations from the Apple Documentation:

    UIInterfaceOrientationUnknown

    The orientation of the device cannot be determined.

    UIInterfaceOrientationPortrait

    The device is in portrait mode, with the device held upright and the home button on the bottom.

    UIInterfaceOrientationPortraitUpsideDown

    The device is in portrait mode but upside down, with the device held upright and the home button at the top.

    UIInterfaceOrientationLandscapeLeft

    The device is in landscape mode, with the device held upright and the home button on the left side.

    UIInterfaceOrientationLandscapeRight

    The device is in landscape mode, with the device held upright and the home button on the right side.

提交回复
热议问题