获取当前界面方向的不同方法? [英] Different ways of getting current interface orientation?

查看:76
本文介绍了获取当前界面方向的不同方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有三种获取当前界面方向的方法:

There're 3 ways to get current interface orientation that I know of:


  • self.interfaceOrientation

  • [[UIApplication sharedApplication] statusBarOrientation]

  • [[UIDevice currentDevice] orientation]

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

它们之间有什么区别?

推荐答案

self.interfaceOrientation 返回UIInterfaceOrientation,界面的当前方向。它是UIViewController中的一个属性,你只能在UIViewController类中访问它。

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] 返回UIInterfaceOrientation,即应用程序状态栏的当前方向。您可以在应用程序的任何位置访问该属性。我的经验表明,这是检索真实界面方向的更有效方法。

[[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] 返回 UIDeviceOrientation ,设备方向。您可以在应用程序的任何位置访问该属性。但请注意,UIDeviceOrientation并不总是UIInterfaceOrientation。例如,当您的设备位于普通桌面上时,您可以获得意外的价值。

[[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.

这篇关于获取当前界面方向的不同方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆