UIDeviceOrientation 和 UIInterfaceOrientation 设备旋转的用法 (实例)
UIDeviceOrientation 是机器硬件的当前旋转方向 这个你只能取值 不能设置
UIInterfaceOrientation 是你程序界面的当前旋转方向 这个可以设置
判断设备现在的方向:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {//宣告一個UIDevice指標,並取得目前Device的狀況UIDevice *device = [UIDevice currentDevice] ; //取得當前Device的方向,來當作判斷敘述。(Device的方向型態為Integer)switch (device.orientation) {case UIDeviceOrientationFaceUp:NSLog(@"螢幕朝上平躺");break;case UIDeviceOrientationFaceDown:NSLog(@"螢幕朝下平躺");break;//系統無法判斷目前Device的方向,有可能是斜置 case UIDeviceOrientationUnknown:NSLog(@"未知方向");break;case UIDeviceOrientationLandscapeLeft:NSLog(@"螢幕向左橫置");break;case UIDeviceOrientationLandscapeRight:NSLog(@"螢幕向右橫置");break;case UIDeviceOrientationPortrait:NSLog(@"螢幕直立");break;case UIDeviceOrientationPortraitUpsideDown:NSLog(@"螢幕直立,上下顛倒");break;default:NSLog(@"無法辨識");break;}// Return YES for supported orientationsreturn (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); // 只支持向左横向, YES 表示支持所有方向 }
或者
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;if (UIDeviceOrientationIsLandscape(deviceOrientation)) NSLog(@"横向"); else if(UIDeviceOrientationIsPortrait(deviceOrientation)) NSLog(@"纵向");// // Return YES for supported orientationsreturn (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); // 只支持向左横向, YES 表示支持所有方向 }
Portrait 表示 纵向,Landscape 表示 横向。
typedef enum {UIDeviceOrientationUnknown,UIDeviceOrientationPortrait, // Device oriented vertically, home button on the bottomUIDeviceOrientationPortraitUpsideDown, // Device oriented vertically, home button on the topUIDeviceOrientationLandscapeLeft, // Device oriented horizontally, home button on the rightUIDeviceOrientationLandscapeRight, // Device oriented horizontally, home button on the leftUIDeviceOrientationFaceUp, // Device oriented flat, face upUIDeviceOrientationFaceDown // Device oriented flat, face down } UIDeviceOrientation;
typedef enum {UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight,UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft } UIInterfaceOrientation;
#define UIDeviceOrientationIsPortrait(orientation) ((orientation) == UIDeviceOrientationPortrait || (orientation) == UIDeviceOrientationPortraitUpsideDown) #define UIDeviceOrientationIsLandscape(orientation) ((orientation) == UIDeviceOrientationLandscapeLeft || (orientation) == UIDeviceOrientationLandscapeRight)
上面是重要的源代码,已经解释的非常清楚。UIDeviceOrientationIsPortrait(orientation) 跟 ((orientation) == UIDeviceOrientationPortrait || (orientation) == UIDeviceOrientationPortraitUpsideDown) 完全是一个意思。
UIDeviceOrientation 和 UIInterfaceOrientation 设备旋转的用法 (实例)相关推荐
- UIDeviceOrientation 和 UIInterfaceOrientation 设备旋转的用法 (实例) 和 IOS6屏幕旋转详解
1. UIDeviceOrientation 和 UIInterfaceOrientation 设备旋转的用法 (实例) 博客分类: IOS / Objective-C UIDeviceOrienta ...
- python pygame鼠标点击_Python中pygame的mouse鼠标事件用法实例
本文实例讲述了Python中pygame的mouse鼠标事件用法.分享给大家供大家参考,具体如下: pygame.mouse提供了一些方法获取鼠标设备当前的状态 ''' pygame.mouse.ge ...
- linux 关联数组,Linux shell数组与关联数组的用法实例
Linux shell数组与关联数组的用法实例 1. 关联数组 使用 declare -A(declare 的用法请使用 help 进行查看,help declare) 进行声明关联数组变量: $ d ...
- python命令行参数解析OptionParser类用法实例
python命令行参数解析OptionParser类用法实例 本文实例讲述了python命令行参数解析OptionParser类的用法,分享给大家供大家参考. 具体代码如下: from opt ...
- php中 datalist,html5 datalist标签的用法是什么?这里有datalist标签的用法实例
本篇文章主要为大家讲述了关于html5 datalist标签的用法及html5 datalist标签的用法实例.本文说了两个常用的选项框的实例供大家选择观看,下面就让我们一起来看这篇文章吧 我们先来看 ...
- python的for语句用法_python中list循环语句用法实例
本文实例讲述了python中list循环语句用法.分享给大家供大家参考.具体用法分析如下: Python 的强大特性之一就是其对 list 的解析,它提供一种紧凑的方法,可以通过对 list 中的每个 ...
- CStopWatch计时器的用法实例
CStopWatch计时器的用法实例 创建CStopWatch对象: CStopWatch m_runningtimeWatch; //定义一个计时器 定义一个装返回值的变量: double m_ru ...
- Go语言MD5加密用法实例
Go语言MD5加密用法实例 本文实例讲述了Go语言MD5加密用法.分享给大家供大家参考.具体实现方法如下: 复制代码 代码如下: import ( "crypto/md5" ...
- python mysqldb cursor_python中MySQLdb模块用法实例
转载自:http://www.jb51.net/article/57290.htm 姓名:梅金波 学号:16010110036 [嵌牛导读]MySQLdb ...
最新文章
- newinsets用法java_Java XYPlot.setInsets方法代碼示例
- ASP连接Access2013
- 坦白局!一个大厂 Java 工程师近 20 年的进阶心得
- zimbra邮件服务器配置,Zimbra邮件服务器无需登录任意邮箱伪造漏洞修复
- matlab 雷达图函数,R语言之可视化(20)ggradar雷达图
- 课程设计---停车场管理系统
- Windows 活动目录(AD)服务器系统升级到2012之升级完成后工作(八)
- 泰勒及洛朗展开学习笔记
- 人工智能超强面经:文本检测与GAN篇(含答案)
- machine id linux,linux – 机器ID是uuid吗?
- 用vs2003调试asp的方法和体会
- Atitit sql执行计划
- 第三章 python流程控制
- Android问题解决--“StorageManager.getVolumeList NullPointerException”空指针再现,getExternalDirs
- 数据库索引:位图索引
- 【Java】指定【微信】好友自动发送消息
- ipa shell自动打包
- STM32CubeMX | | 使用小熊派串口驱动峰汇ETH-01以太网模块上传数据到OneNet
- 如何制作RJ45超五类线缆?六个步骤搞定!
- Linux 内存映射之文件映射
热门文章
- 信息学奥赛C++语言:质因数分解
- 合唱团算法(DP问题)
- 笔记本安装centos7.6网络的配置_可以放入口袋里面的笔记本电脑:国产黑科技,户外工程师必备利器...
- 三年硬件工程师薪水_谷歌员工基本薪资曝光:软件工程师最高 241 万,工程副总裁 325 万,产品经理、UX 171 万,硬件工程师 166 万...
- hat怎么安装mysql_Red Hat Enterprise Linux中怎么安装Mysql+apache+php+zend
- linux /dev
- OpenCV Mat主要用法(2)_MatExpr
- python简写匹配_Python简写
- windows定时任务python shutil_python- shutil 高级文件操作
- caffe,deeplab,对Interp(差值)层的理解