How to force view controller orientation in iOS 8?

前端 未结 25 2392
太阳男子
太阳男子 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:32

    This should work from iOS 6 on upwards, but I've only tested it on iOS 8. Subclass UINavigationController and override the following methods:

    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
        return UIInterfaceOrientationLandscapeRight;
    }
    
    - (BOOL)shouldAutorotate {
        return NO;
    }
    

    Or ask the visible view controller

    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
        return self.visibleViewController.preferredInterfaceOrientationForPresentation;
    }
    
    - (BOOL)shouldAutorotate {
        return self.visibleViewController.shouldAutorotate;
    }
    

    and implement the methods there.

提交回复
热议问题