iOS屏幕自动旋转 以及横屏模式打开APP出现的问题
首先 项目配置 设置支持方向
创建 UINavigationController父类、 tabbar 父类 、 uiviewcontroller 父类
UINavigationController.m 中实现
- (BOOL)shouldAutorotate {if([self.topViewController respondsToSelector:@selector(shouldAutorotate)]){return [self.topViewController shouldAutorotate];}return NO;
}- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{if([self.topViewController respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)]){return [self.topViewController supportedInterfaceOrientations];}return [super supportedInterfaceOrientations];
}-(UIInterfaceOrientation) preferredInterfaceOrientationForPresentation
{if([self.topViewController respondsToSelector:@selector(preferredInterfaceOrientationForPresentation)]){return [self.topViewController preferredInterfaceOrientationForPresentation];}return [super preferredInterfaceOrientationForPresentation];
}
tabBarControllerViewController.m 中实现
// 是否支持旋转屏幕
-(BOOL)shouldAutorotate
{return [self.selectedViewController shouldAutorotate];
}// 如果支持旋转屏幕,支持旋转屏幕的方向
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{return [self.selectedViewController supportedInterfaceOrientations];
}// 默认屏幕的方向
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{return [self.selectedViewController preferredInterfaceOrientationForPresentation];
}
uiviewcontroller.m 父类 中实现
// 默认不能旋转
-(BOOL)shouldAutorotate {return NO;
}默认只支持竖屏
-(UIInterfaceOrientationMask)supportedInterfaceOrientations {return UIInterfaceOrientationMaskPortrait;
}- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {return UIInterfaceOrientationPortrait;
}
在需要设置横屏页面设置
//支持屏幕旋转
-(BOOL)shouldAutorotate
{return YES;
}
// 支持屏幕旋转方向
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{return UIInterfaceOrientationMaskAll;// 全部方向(设备支持方向)
}
// 默认打开方向
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{return UIInterfaceOrientationPortrait;
}
遇到设备横屏打开APP 会按照横屏来布局
需要在 如下方法中添加
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];//此方法
}
(其他情况 若:你在didFinishLaunchingWithOptions中 加载了另一个 window 的时候,需要在改 window 中也遵守屏幕旋转的几个代理方法 否则横屏模式下打开APP布局依然会乱)
iOS屏幕自动旋转 以及横屏模式打开APP出现的问题相关推荐
- windows禁用屏幕旋转_如何在Windows 10中禁用屏幕自动旋转
windows禁用屏幕旋转 Windows 10 can automatically rotate your display if you have a convertible PC or table ...
- iOS开发屏幕自动旋转与调整大小
原文链接地址: http://ytwhw.iteye.com/blog/1767465 在此谢谢原博主的精心整理! 关注小白,共同成长! 苹果的产品iPad和iPhone都是支持自动旋转的,因而我们写 ...
- ios屏幕的旋转,Device Orientation
屏幕旋转,我的理解是ios设备根据重力感应改变屏幕的方向.那么如何在屏幕转动后变换UI?或则保持原样呢? ios设备支持4个方向,UIInterfaceOrientationPortrait,UIIn ...
- android禁止屏幕自动旋转_如何禁止屏幕翻转
Android 版需要修改 AndroidManifest.xml 文件,在文件中找到 android:screenOrientation 属性,原值应该是 user,修改成 portrait 就是锁 ...
- 关于IOS屏幕的旋转问题
处理IPhone屏幕的旋转是我们经常遇到的,当你做一个应用既然满足竖屏又要满足横屏,这就要求我们会处理屏幕旋转的问题! 方法一:自动布局 1.将项目中界面的四种手持方式都点上: 2.取消Use Aut ...
- iOS架构-自动打包并上传到App Store(python)(21)
这里是摘自一篇用python 语法写的脚本,这里只是为了更好的理解自动化打包上传App Store的原理的. 一. iOS 自动打包并上传到App Store(python) 我们平时大都是用Appl ...
- IOS 图片自动旋转
+ (UIImageView *)rotate360DegreeWithImage View:(UIImageView *)imageView{ CABasicAnimation *ani ...
- iphone应用程序中禁止屏幕自动旋转 自定义屏幕旋转
在summary中的 supported devices orientation中设置所支持的屏幕旋转方式在实际RUN时并不会应用所选项目,正确的禁止屏幕旋转方向以及自定义屏幕旋转方式要在viewco ...
- uniapp禁止屏幕自动旋转
1.第一步:在App.vue里添加以下代码: onLaunch: function() {// 禁止横屏// #ifdef APP-PLUSplus.screen.lockOrientation(&q ...
最新文章
- 跟郎朗媳妇有得一拼的AI,只看弹琴动作,完美复现原声 | CVPR 2020
- mysql运行正确结果显示_以下代码执行的结果是()
- Twiiter,下一个热点
- 第2题——DNA片段
- 数据库-ADONET-在数据集DataSet中使用关系对象DataRelation处理关系
- 混合文件下分离xml文件和jpg文件
- win10html中文乱码,Win10预览版10125中文语言包安装及乱码解决方法
- c语言高低位拷贝_C语言指针详解
- 链表的翻转(迭代法 递归法)
- 新开普自助查询 单点登录 php,综合教务管理系统,高校教务管理系统,教务管理系统 - 新开普(NewCapec)...
- 事务的acid属性是指_Mysql事务的性质 为什么要用事务?
- 佳能Canon PIXMA MG3020 打印机驱动
- 维特智能陀螺仪角度传感器原理
- vcenter访问报503错误处理
- java中的radix_int radix()
- Unity高质量场景打光参考资料
- 静态路由(也许是目前最全的)
- 资本寒冬之下的聚美优品私有化
- 一条大蟒蛇和一条小毒蛇
- Ubuntu 16.04 LTS 初体验