三种方式:

  • self.interfaceOrientation
  • [[UIApplication sharedApplication] statusBarOrientation]
  • [[UIDevice currentDevice] orientation]

但是实际使用时有区别的:

self.interfaceOrientation returns UIInterfaceOrientation, current orientation of the interface. It is a property in UIViewController, you can access to this one only in UIViewController classes.

[[UIApplication sharedApplication] statusBarOrientation] returns UIInterfaceOrientation, current orientation of the application's status bar. You can access to that property in any point of your application. My experience shows that it's more effective way to retrieve real interface orientation.

[[UIDevice currentDevice] orientation] returns UIDeviceOrientation, device orientation. You can access to that property in any point of your application. But note that UIDeviceOrientation is not always UIInterfaceOrientation. For example, when your device is on a plain table you can receive unexpected value.

原文:http://stackoverflow.com/questions/7968451/different-ways-of-getting-current-interface-orientation

iOS获取当前设备方向的更多相关文章

  1. IOS 获取最新设备型号方法

    1.IOS 获取最新设备型号方法列表最新对照表:http://theiphonewiki.com/wiki/Models方法: #import "sys/utsname.h” struct ...

  2. iOS获取用户设备崩溃日志并分析

    项目最近发布,部分用户在内侧使用,正好遇到一些问题,由于用户在其他城市,所以对于用户设备产生的崩溃日志,不好直接拿设备连接电脑. 对于这种情况,我们可以这样: 1.引导用户开启iOS设备设置-> ...

  3. iOS 获取摄像头当前方向

    在做二维码扫描和直播获取视频流的过程中,可能会用到 AVCaptureDevice AVCaptureVideoPreviewLayer AVCaptureSession 这几个参数,其中 1.定义显 ...

  4. ios 获取当前设备信息、内存

    //在[UIDevice currentDevice]中的属性 @property(nonatomic,readonly,strong) NSString *name; // e.g. "M ...

  5. IOS获取手机设备型号

    最新型号的设备列表https://www.theiphonewiki.com/wiki/Models #import "iosutils/IOSUtils.h" #import & ...

  6. ios 获取手机设备信息

    [UIDevice currentDevice]:表示设备 NSString *devices=[[NSString alloc] initWithFormat: @"unique id: ...

  7. IOS获取手机设备所有应用

    //返回一个数组 1 NSMutableArray *applist = [[NSMutableArray alloc]init]; NSString *pathOfApplications = @& ...

  8. IOS 特定于设备的开发:处理基本方向

    UIDevice类使用内置的orientation属性获取设备的物理方向.IOS设备支持这个属性的7个可能的值. >UIDeviceOrientationUnknown:方向目前未知. > ...

  9. iOS获取设备唯一标识的8种方法

    8种iOS获取设备唯一标识的方法,希望对大家有用. UDID UDID(Unique Device Identifier),iOS 设备的唯一识别码,是一个40位十六进制序列(越狱的设备通过某些工具可 ...

随机推荐

  1. mysql 碎片清理

    在MySQL中,我们经常会使用VARCHAR.TEXT.BLOB等可变长度的文本数据类型.不过,当我们使用这些数据类型之后,我们就不得不做一些额外的工作——MySQL数据表碎片整理. 那么,为什么在使 ...

  2. Java9模块化(Jigsaw)初识

    Java9经历了多次跳票,终于要在9月份正式发布,原计划Jigsaw在Java7就有的,也终于在Java9里面提供了,简单总结下. 对比 Java9 以前 上面2个图分别对应的分别是JDK8/9的目录 ...

  3. javascript函数的四种调用模式及其this关键字的区别

    方法调用模式: 当一个函数被保存为对象的一个属性时,我们称它为一个方法.当一个方法被调用时,this被绑定到该对象. //方法调用模式 var myObject = { value: 0 , incr ...

  4. android4.1 JELLY_BEAN:All WebView methods must be called on the same thread[问题已解决]

    11-06 18:29:15.582: W/WebView(27807): java.lang.Throwable: A WebView method was called on thread 'Ja ...

  5. gmock学习01---Linux配置gmock

    本文目的 本文主要介绍gmock 1.6.0版本在Linux上如何部署和使用. gmock是做什么的? 使用C++手动编写mock对象将会是一件十分耗时,易于出错,枯燥乏味的事情.gmock提供一整套 ...

  6. pymongo 目标计算机积极拒绝

    今天在使用pymongo连接服务器上的mongodb数据库时出现该问题 其实原因是mongodb本身配置只允许本机连接数据库 打开mongod.conf即mongodb的配置文件 一般来说是vim / ...

  7. scrapy爬虫框架实例一,爬取自己博客

    本篇就是利用scrapy框架来抓取本人的博客,博客地址:http://www.cnblogs.com/shaosks scrapy框架是个比较简单易用基于python的爬虫框架,相关文档:http:/ ...

  8. kubernetes 部署SonarQube 7.1 关联LDAP

    之前有写过一篇如何在kubernetes上部署SonarQube的文档, 然后由于客户的需求,需要SonarQube关联LDAP的用户, 于是今天花了半天时间研究了以下如何在原有的基础上安装LDAP插 ...

  9. CSS学习(九)-CSS背景

    一.理论: 1.background-break  a.bounding-box 背景图像在整个内联元素中进行平铺 b.each-box 背景图像在行内中进行平铺 c.continuous 下一行的背 ...

  10. MySQL外键及级联删除 && 表的存储引擎与创建索引 && 删除数据库和表

    Messages表: mysql>create table Messages( ->message_id int auto_increment primary key, ->user ...