iOS 屏幕旋转相关

旋转屏幕问题

1、如果是单纯的控制器,没有自定义的NavigationController进行嵌套。

/**
 旋转屏幕问题,必备三要素
 shouldAutorotate
 supportedInterfaceOrientations
 preferredInterfaceOrientationForPresentation
 */
- (BOOL)shouldAutorotate { // 是否支持自动旋转 默认 YES, NO:不自动旋转屏幕,定死一个方向
    return YES;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations { // 设置 程序支持的哪些方向(位枚举)
    return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { // 设置默认的方向
    return UIInterfaceOrientationLandscapeRight;
}

2、如果有自定义的NavigationController进行嵌套。先 这样,然后再设置 1

//  如果嵌套了一层navigationController的话,需要在navigaController中实现这三个方法
//  类似于我们设置 电池条颜色或者状态栏显示隐藏状态一样
 
 - (BOOL)shouldAutorotate {
     return [self.topViewController shouldAutorotate];
 }

 - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
     return [self.topViewController supportedInterfaceOrientations];
 }

 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
     return [self.topViewController preferredInterfaceOrientationForPresentation];
 }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容