iOS纯代码实现 强制横屏

iOS9.0强制横屏

适用于“当需要在某个竖屏的情况下点击一个按钮跳转到另一个横屏的controller”

  • 首先 :在UINavigationViewController.m中重写以下三个方法,目的是为了在页面跳转和返回的时候让一级二级controller都找到自己支持的横竖屏模式,否则从横屏返回的时候会出现崩溃的情况
- (BOOL) shouldAutorotate {    
    return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations { 
    return [self.viewControllers.lastObject supportedInterfaceOrientations];
}
- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
    return [self.viewControllers.lastObject referredInterfaceOrientationForPresentation];
}
  • 其次 :在你需要横屏的那个第二级controller.m里面重写三个方法:
- (BOOL)shouldAutorotate {
    return YES;
}
- (UIInterfaceOrientationMask) supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
**//此处填写你需要让第二级controller现实的横屏方向**
    return UIInterfaceOrientationLandscapeLeft;
}
  • 最后:要注意一些细节点,只能用present不能用push.

要看的更真切的话,用代码说话.
请转到我的github:https://github.com/FocusLyn/LandscapeLeft

That's all. Thx reading.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容