iOS横向左对右对错 [英] iOS Landscape Left vs Right vs Wrong

查看:66
本文介绍了iOS横向左对右对错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL; DR:iOS文档不同意 Info.plist ,即哪个方向(横向左向右)在哪一侧具有主页按钮.我想念什么吗?(例如,代码认为所处的方向与设备知道所处的方向之间存在区别.请参阅倒数第二个要点在下面标有❓的地方.)

但是,当我在Xcode中使用常规"复选框时, Info.plist 文件显示为相反:

以上信息清楚地表明了矛盾.我的问题是:我是否缺少某些东西,还是应该将其视为工具链/docs/API中的持久残cru?


当您在模拟器或设备上运行应用程序时,实际上会发生什么 ?以下是我收集的数据的子集.为了您的阅读方便,我强调了术语左"和右".您的大脑可能仍会爆炸.

要跟踪三个数量:

  • Xcode/plist怎么说
  • 模拟器"菜单项显示的内容[或设备方向]
  • API调用 UIDevice.current.orientation 怎么说.

将常规"复选框设置为仅 "为左横向" :

  • Info.plist 文件显示"Landscape(左侧主屏幕按钮)" [即不同意文档]
  • 模拟器启动
    • 屏幕图像朝上[即正确]
    • 已选中硬件">方向"菜单项右横向" [即不同意Xcode/plist]
    • 带有左侧的主页按钮[即菜单项和主页按钮位置之间的关系与文档一致]
  • UIDevice.current.orientation == .landscapeRIGHT [即不同意Xcode,但同意模拟器菜单]
  • 选择菜单项硬件">方向">横向左"
    • 将屏幕图像上下翻转[正确的行为:无图像自动旋转]
    • 在右侧放置主页按钮[当然]
    • UIDevice.current.orientation == .landscapeLEFT [与docs/相反,与Xcode/plist一致]
  • 使用左侧的主页按钮启动iPhone:
    • 正确显示屏幕图像
    • UIDevice.current.orientation == .landscapeRIGHT [与docs/相反,与Xcode/plist一致]
  • 将手机旋转180度
    • 在右侧放置主页按钮[当然]
    • UIDevice.current.orientation == .landscapeRIGHT [即它与应用程序认为进行的操作一致,而不与设备的物理方向一致.
  • iPad的行为与iPhone相同

解决方案

我认为主要是Xcode UI和info.plist之间的矛盾.Xcode UI显示"设备方向",而info.plist则说支持的接口方向".但是据我们所知,这是两回事,所以那里肯定有问题.

假设两者之间的info.plist 获胜,然后使用这些字段(适用于iPhone和iPad)指定受支持的界面方向.IE.您还可以通过 supportedInterfaceOrientations 在特定视图控制器中覆盖的选项相同.

相反,引用的文档页面是关于设备方向的,它对 landscapeLeft 的定义是自己的:右侧的主页按钮.

现在,查看界面方向蒙版而是具有 landscapeLeft 的详细信息:左侧的主页按钮,如旧屏幕截图所示.

结论

总而言之,在我看来:

  1. Xcode UI/info.plist与支持的界面方向有关,该界面具有自己的左右横向定义

  2. 设备方向与左/右横向定义相反

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

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

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

解决方案

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:

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

这篇关于iOS横向左对右对错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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