2)UIInterfaceOrientationMask的应用
在ViewController可以重写- (UIInterfaceOrientationMask)supportedInterfaceOrientations办法返回类型,来决定UIViewController可以支撑哪些界面偏向。
- //支撑界面竖立
- - (UIInterfaceOrientationMask)supportedInterfaceOrientations{
- return UIInterfaceOrientationMaskPortrait;
- }
总结:UIDeviceOrientation(设备偏向)和UIInterfaceOrientation(屏幕偏向)是两个不合的概念。前者代表了设备的一种状况,而后者是屏幕为了应对不合的设备状况,做出的用户界面上的响应。在iOS设备扭转时,由UIKit接收到扭转事宜,然后经由过程AppDelegate通知当前法度榜样的UIWindow对象,UIWindow对象通知它的rootViewController,如不雅该rootViewController支撑扭转后的屏幕偏向,完成扭转,不然不扭转;弹出的ViewController也是如斯处理。
二、视图控制器中扭转偏向的设置
比较惯例的办法有两种。
办法1:在项目标General–>Deployment Info–>Device Orientation中,只勾选Portrait(竖屏)
勾选Portrait.png
办法2:Device Orientation默认设置,在Appdelegate中实现supportedInterfaceOrientationsForWindow:只返回UIInterfaceOrientationMaskPortraitt(竖屏)
- - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
- return UIInterfaceOrientationMaskPortrait;
- }
0、关于禁止横屏的操作(不建议)
一、监听屏幕扭转偏向
下面介绍若何让项目中的 视图控制器中扭转偏向的设置
1、APP支撑多个偏向
APP支撑多个偏向.png
解释:如斯,APP支撑横屏和竖屏了,然则具体视图控制器支撑的页面偏向还须要进一步处理。因为不支撑竖屏倒置(Upside Down),即使设备高低倒置,经由过程API也不会获得设备、屏幕高低倒置偏向的。
2、支撑ViewController屏幕偏向设置
1)关键函数
视图控制器支撑的界面偏向重要由以下三个函数控制
- //是否主动扭转,返回YES可以主动扭转,返回NO禁止扭转
- - (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED;
- //返回支撑的偏向
- - (UIInterfaceOrientationMask)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED;
推荐阅读
近年来,Python 在数据科学行业扮演着越来越重要的角色。是以,我根据比来的应用体验,在本文中列出了对数据科学家、工程师们最有效的那些库。因为这些库都开源了,我们大年夜Github上惹人>>>详细阅读
本文标题:代码处理iOS的横竖屏旋转
地址:http://www.17bianji.com/lsqh/36388.html
1/2 1