9

TL;DR: The iOS docs disagree with Info.plist about which orientation (landscape left vs. right) has the home button on which side. Am I missing something? (For example, there is a distinction between what orientation the code thinks it is in, and the orientation the device knows it is in. See next-to-last bullet point labeled ❓ below.)

The doc for UIDeviceOrientation says

screenshot from docs

However, when I use the General checkbox in Xcode, the Info.plist file says the opposite:

screenshots from Xcode

The above info presents the contradiction clearly enough. My question is: am I missing something or should I just take this as long-lasting cruft in the toolchain/docs/API?


What actually happens when the app runs on the Simulator or devices, you ask? The following is a subset of the data I have collected. For your reading convenience, I have emphasized the terms LEFT and RIGHT. Your brain may still explode.

There are three quantities to track:

  • What Xcode/plist say
  • What the Simulator menu items say [or what device orientation is]
  • What the API call UIDevice.current.orientation says.

When the General checkbox is set solely to "Landscape LEFT":

  • The Info.plist file says "Landscape (LEFT home button)" [i.e. disagrees with documentation]
  • The Simulator launches
    • with screen image up-side-up [i.e. correctly]
    • with Hardware > Orientation menu item "Landscape RIGHT" checked [i.e. disagrees with Xcode/plist]
    • with home button on LEFT [i.e. relation between menu item and home button location agrees with docs]
  • UIDevice.current.orientation == .landscapeRIGHT [i.e. disagrees with Xcode, but agrees with Simulator menu]
  • Choosing menu item Hardware > Orientation > Landscape LEFT
    • flips the screen image to upside-down [correct behavior: no image auto-rotate]
    • puts home button on RIGHT [of course]
    • UIDevice.current.orientation == .landscapeLEFT [consistent with docs/contrary to Xcode/plist]
  • Launching iPhone with home button on LEFT:
    • shows screen image correctly
    • UIDevice.current.orientation == .landscapeRIGHT [consistent with docs/contrary to Xcode/plist]
  • Rotating the phone 180°
    • puts home button on RIGHT [of course]
    • UIDevice.current.orientation == .landscapeRIGHT [i.e. it's consistent with what the app thinks is going on, not with the physical orientation of the device]
  • iPad behaves same as iPhone
Andrew Duncan
  • 3,553
  • 4
  • 28
  • 55
  • Can you check your info.plist Source? For me when I went to replicate this in new project, it created a new array with the only one orientation supported. but another array is there with all the orientations supported? Looking into what issues this may cause, but also still trying to replicate this, its fascinating. This would explain why. Here's what my plist source shows with the box checked. https://imgur.com/a/MvswGVk – NSGangster Mar 13 '19 at 21:35
  • now two sets of arrays show up in my gui plist, let me look a bit more – NSGangster Mar 13 '19 at 21:41
  • Hmm where are you getting the programmatic interface from? AppDelegate? I am registering for `UIDevice.orientationDidChangeNotification` in rootViewController and it gets triggered 3 times. "right" "left" "left" when starting simulator. gonna try physcial device and see if I reproduce this. – NSGangster Mar 13 '19 at 22:04
  • but otherwise looks like everything matches up besides the plist – NSGangster Mar 13 '19 at 22:05
  • The question actually only applies to a project with *only one* permitted orientation. I did use `viewWillTransition(to:with:)` to look at orientations, but didn't look at the Notifications. To get the orientation programmatically, at any time (not just transitions) I have a button on the screen that just prints `UIDevice.current.orientation` to the console. – Andrew Duncan Mar 13 '19 at 23:12
  • However, looking at the plist XML source is something I didn't think of. When configured as in the above screenshots, the `UISupportedInterfaceOrientations` array has the one value `UIInterfaceOrientationLandscapeLeft`. Contradiction between Xcode and API remains. – Andrew Duncan Mar 13 '19 at 23:16
  • Oh, also, @NSGangster, the second array, with all orientations supported, is specifically for iPad only. Its key is `UISupportedInterfaceOrientations~ipad`. I am in the habit of renaming the first key with a `~iphone` suffix. – Andrew Duncan Mar 13 '19 at 23:19
  • I've seen the same experience, and it causes quite a bit of confusion for developers when testing fixed orientation apps in the simulator. – Scott D Aug 31 '19 at 13:04
  • Something I had forgotten to do: call `UIDevice.current.beginGeneratingDeviceOrientationNotifications()`. – Andrew Duncan May 27 '20 at 18:51

1 Answers1

7

I think mainly it's a matter of a contradiction between Xcode UI and info.plist. Xcode UI shows "Device Orientation", while info.plist speaks about "Supported Interface Orientation". But as we know those two are different things, so there's definitely something wrong there.

Assuming, between the two, that info.plist wins then those fields (for iPhone and iPad) are used to specify Supported Interface Orientation. I.e. the same option that you can also override in a specific view-controller through supportedInterfaceOrientations.

Instead the referenced doc page is about Device Orientation, with its own definition of what is landscapeLeft: home button to the right.

Now, looking at Interface Orientation Mask docs, there's no real detail on what is landscapeLeft, but old Xcode UI screenshots show that home button is to the left. See e.g. from this SO thread:

enter image description here

EDIT: Interface Orientation doc page instead has detail on what is landscapeLeft: home button to the left, as shown in old screenshots.

Conclusions

So, all in all, it seems to me that:

  1. Xcode UI/info.plist are about supported interface orientation, which has its own definition of landscape left/right

  2. Device orientation has the opposite definition of landscape left/right

superjos
  • 12,189
  • 6
  • 89
  • 134
  • You describe a schizophrenic situation.. but I think you are correct. No wonder it is confusing, at first (second, third) glance. – Andrew Duncan Sep 20 '19 at 15:59
  • I agree, but that's what I can see as of now. Device and Interface definitions in the official docs are definitely at the opposite. This is a fact, as of today. Then Xcode UI and info.plist are different too, but judging from previous UI screenshots, the right one seems to be the plist definition. – superjos Sep 20 '19 at 16:29
  • 2
    I just came across this comment in `UIApplication.h` that either sheds some light. It has been dawning on me that *device* and *content* orientations are two different things. "Note that `UIInterfaceOrientationLandscapeLeft` is equal to `UIDeviceOrientationLandscapeRight` (and vice versa). This is because rotating the device to the left requires rotating the content to the right." – Andrew Duncan May 27 '20 at 18:47