UIDeviceOrientation      是机器硬件的当前旋转方向   这个你只能取值 不能设置

UIInterfaceOrientation   是你程序界面的当前旋转方向   这个可以设置

判断设备现在的方向:

  1. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  2. {
  3. UIDevice *device = [UIDevice currentDevice] ;
  4. //取得當前Device的方向,來當作判斷敘述。(Device的方向型態為Integer)
  5. switch (device.orientation) {
  6. case UIDeviceOrientationFaceUp:
  7. NSLog(@"螢幕朝上平躺");
  8. break;
  9. case UIDeviceOrientationFaceDown:
  10. NSLog(@"螢幕朝下平躺");
  11. break;
  12. //系統無法判斷目前Device的方向,有可能是斜置
  13. case UIDeviceOrientationUnknown:
  14. NSLog(@"未知方向");
  15. break;
  16. case UIDeviceOrientationLandscapeLeft:
  17. NSLog(@"螢幕向左橫置");
  18. break;
  19. case UIDeviceOrientationLandscapeRight:
  20. NSLog(@"螢幕向右橫置");
  21. break;
  22. case UIDeviceOrientationPortrait:
  23. NSLog(@"螢幕直立");
  24. break;
  25. case UIDeviceOrientationPortraitUpsideDown:
  26. NSLog(@"螢幕直立,上下顛倒");
  27. break;
  28. default:
  29. NSLog(@"無法辨識");
  30. break;
  31. }
  32. // Return YES for supported orientations
  33. return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); // 只支持向左横向, YES 表示支持所有方向
  34. }

或者

  1. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  2. {
  3. UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
  4. if (UIDeviceOrientationIsLandscape(deviceOrientation)) NSLog(@"横向");
  5. else if(UIDeviceOrientationIsPortrait(deviceOrientation)) NSLog(@"纵向");
  6. // // Return YES for supported orientations
  7. return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); // 只支持向左横向, YES 表示支持所有方向
  8. }

Portrait 表示 纵向,Landscape 表示 横向。

  1. typedef enum {
  2. UIDeviceOrientationUnknown,
  3. UIDeviceOrientationPortrait,            // Device oriented vertically, home button on the bottom
  4. UIDeviceOrientationPortraitUpsideDown,  // Device oriented vertically, home button on the top
  5. UIDeviceOrientationLandscapeLeft,       // Device oriented horizontally, home button on the right
  6. UIDeviceOrientationLandscapeRight,      // Device oriented horizontally, home button on the left
  7. UIDeviceOrientationFaceUp,              // Device oriented flat, face up
  8. UIDeviceOrientationFaceDown             // Device oriented flat, face down
  9. } UIDeviceOrientation;
  1. typedef enum {
  2. UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,
  3. UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
  4. UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,
  5. UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft
  6. } UIInterfaceOrientation;
  1. #define UIDeviceOrientationIsPortrait(orientation)  ((orientation) == UIDeviceOrientationPortrait || (orientation) == UIDeviceOrientationPortraitUpsideDown)
  2. #define UIDeviceOrientationIsLandscape(orientation) ((orientation) == UIDeviceOrientationLandscapeLeft || (orientation) == UIDeviceOrientationLandscapeRight)

上面是重要的源代码,已经解释的非常清楚。UIDeviceOrientationIsPortrait(orientation) 跟  ((orientation) == UIDeviceOrientationPortrait || (orientation) == UIDeviceOrientationPortraitUpsideDown) 完全是一个意思

ios 设备方向判断相关推荐

  1. iOS 设备型号判断及对应固件的选择

    最近整天看着一些人问什么GSM刷什么固件,什么港版插移动卡为什么刷CDMA的固件,真是越解释越黑!其实像IPHONE之所以说什么CDMA版和GSM版完全也是拿小白没办法,要不然越说越糊!就像美版成锁版 ...

  2. [iOS]设备型号判断大全(包括iPhoneX)

    头文件 #import <Foundation/Foundation.h>typedef NS_ENUM(NSInteger,DeviceType) {Unknown = 0,Simula ...

  3. iOS开发入门——模拟器方向判断及基本功能

    iOS开发入门--模拟器方向判断及基本功能 方向判断简单实用 手机模拟器吧,嗯...很多时候我们可能会遇到手机横屏之后图像没变的情况,嗯?怎么回事?这次我们就先来看看这种情况,做一个简单的判断. im ...

  4. 如何判断ios设备中是否安装了某款应用

    如果是Xcode 4.6 ,那么按照下面的方法添加: 解决方案: 从91SDK3.2.5开始要求接入方需要设置一个URL Scheme,设置方法如下:选中工程中的Target,选中Info标签页,找到 ...

  5. IOS基础之iPad的屏幕旋转方向判断

    IOS基础之iPad的屏幕旋转方向判断 #pragma mark - 屏幕旋转 - (void)viewWillTransitionToSize:(CGSize)size withTransition ...

  6. js/css 检测移动设备方向的变化 判断横竖屏幕

    js/css 检测移动设备方向的变化 判断横竖屏幕 方法一:用触发手机的横屏和竖屏之间的切换的事件 window.addEventListener("orientationchange&qu ...

  7. flutter 控制iOS设备屏幕可旋转支持方向

    场景:flutter开发一个app,非module形式,即:app内部大部分页面是横屏,有部分页面是需要视屏显示(不参与喷子:写一个空控件旋转90度不就好了?但是这样的话状态栏之前的状态,如果你不需要 ...

  8. 加速度 陀逻计的设备方向的使用

    加速度计是一种能够感应设备一个方向上线性加速度的传感器 ios设备中有三种方向,为xyz轴, 为三轴的受力情况 先导入coremotion framework框架  在build phases 的li ...

  9. iOS学习——获取iOS设备的各种信息

    不管是在Android开发还是iOS开发过程中,有时候我们需要经常根据设备的一些状态或信息进行不同的设置和性能配置,例如横竖屏切换时,电池电量低时,内存不够时,网络切换时等等,我们在这时候需要进行一些 ...

最新文章

  1. EOS入门指南PART6——别忙着开发,先来看看智能合约数据是怎么存的
  2. metric learning
  3. Oracle数据库导入导出命令imp/exp
  4. windows10设置开机自启动
  5. 鸿蒙系统 新闻,鸿蒙系统升级名单曝光,为什么你还没有收到推送?3个原因望周知...
  6. boost::lambda::member_pointer_action用法的测试程序
  7. PostgreSQL日期函数备忘
  8. 函数的递归调用(专题)
  9. FaceBook机器学习开源DL模块
  10. Java中JFrame怎样控制闪烁_在JFrame Java中闪烁
  11. 高校教师职称制度将迎重大改革,教师怎么看?
  12. java并发包作者lee_Java的一些并发包
  13. 正则表达式和Java编程语言1zz
  14. 66.为什么有时候在ISE软件中,顶层文件不能置顶?
  15. Java变量的默认值和初始化
  16. jedis,spring-redis-data 整合使用,版本问题异常
  17. Arena4D点云数据处理软件简介
  18. OpenCV学习 之 IplImage*遍历每个像素点
  19. python将word文档转图片_如何将word文档转换为图片
  20. 斗鱼封禁主播陈一发,新媒体有出路吗?

热门文章

  1. 使用AI画一个冠状病毒
  2. 走进科学-小菌株大作为—枯草芽孢杆菌替代畜牧业抗生素添加
  3. 回归模型和时间序列模型中的MAPE指标是什么?MAPE指标解读、MAPE越大越好还是越小越好、使用MAPE指标的注意事项
  4. R语言str_sub函数从字符串中提取或替换子字符串(substring):str_sub函数指定起始位置和终止位置抽取子字符、str_sub函数指定起始位置和终止位置替换子字符串
  5. 广义线性模型GLM、GLMM、LMM、MLM、GMM、GEE、广义线性模型GLM和广义线性混合模型的GLMM区别
  6. 阿里云 mysql主从_阿里云MySQL主从_Mater Slave_主备同步_MySQL主从_MySQL延迟-云栖社区-阿里云...
  7. Iterative error correction of long sequencing reads maximizes accuracy and improves contig assembly
  8. STM32-RCC内部总线时钟设置程序详讲
  9. tf.keras.losses.CategoricalHinge 损失函数示例
  10. python 删除 csv 文件的行