Difference between Interface Orientation and Device Orientation?
Asked Answered
T

2

7

What's the Difference between Interface Orientation and Device Orientation? Both of them seems the same but what's the actual difference between them?

Tweet answered 3/5, 2014 at 6:11 Comment(0)
T
12

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. But just because the device is in Portrait doesn't mean your interface is also in portrait. You may require your app to only provide landscape orientation, hence the interface orientation would be different than the device orientation.

Tyranny answered 3/5, 2014 at 6:13 Comment(2)
When choosing orientation in the settings of a project, why are the possible orientations labelled as Device Orientation, when they are clearly referring to UIInterfaceOrientation here and not to UIDeviceOrientation?Variegated
Btw your answer would be even better if you explained why left and right are switched in the enumeration. Is this just a custom so people can tell the interface orientation from where the home button is, or is there a mathematical reason?Variegated
M
2

Following description got from this site.

UIDeviceOrientation is a property of the UIDevice class, and there are these possible values:

  • UIDeviceOrientationUnknown - Can't be determined
  • UIDeviceOrientationPortrait - Home button facing down
  • UIDeviceOrientationPortraitUpsideDown - Home button facing up
  • UIDeviceOrientationLandscapeLeft - Home button facing right
  • UIDeviceOrientationLandscapeRight - Home button facing left
  • UIDeviceOrientationFaceUp - Device is flat, with screen facing up
  • UIDeviceOrientationFaceDown - Device is flat, with screen facing down

As for UIInterfaceOrientation, it is a property of UIApplication and only contains 4 possibilities which correspond to the orientation of the status bar:

  • UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait
  • UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown
  • UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight
  • UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft (copied from docs)

For example, the device (the actual iPhone or iPod) could be in UIDeviceOrientationLandscapeRight but if your app doesn't support that, it (your app) might still be in UIInterfaceOrientationPortrait.

In addition, to get UIDeviceOrientation, you use [[UIDevice currentDevice] orientation], and to get UIInterfaceOrientation, you use [[UIApplication sharedApplication] statusBarOrientation]

More info

Maynardmayne answered 3/5, 2014 at 6:16 Comment(1)
Nice answer! Link seems to be broken thoughTransport

© 2022 - 2024 — McMap. All rights reserved.