Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different ways of getting current interface orientation?

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

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

What are the differences among them?

like image 854
Anh Avatar asked Nov 01 '11 15:11

Anh


People also ask

What is Interface orientation?

Interface Orientation can be anything, regardless of device orientation. Device Orientation is the actual physical orientation of the device you are holding, and this is not variable; it is what it is. If you are holding in Portrait, it is Portrait.


2 Answers

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.

like image 176
beryllium Avatar answered Oct 04 '22 15:10

beryllium


[[UIApplication sharedApplication] statusBarOrientation] - it always equals to one of four values: portrait, landscape left, landscape right and portrait upside down.

[[UIDevice currentDevice] orientation] - this one equals to standart four values and also: unknown, face up or face down.

[[UIApplication sharedApplication] statusBarOrientation] - is more prefered way to get interface orientation.

like image 28
holodnyalex Avatar answered Oct 04 '22 14:10

holodnyalex