【问题标题】:Different UIScreen bounds returned by iOS7 and iOS8 [duplicate]iOS7和iOS8返回的不同UIScreen边界[重复]
【发布时间】:2014-12-13 14:05:08
【问题描述】:

我为 Deployment target >= 7.1 制作应用程序。我看到了“错误”...... 应用程序只能在横向模式下运行!

代码:

CGSize frameSize = [[UIScreen mainScreen] bounds].size;

在 iOS 7 (iPhone 4) 中,返回 CGSize (width=320, height=480),但必须返回 480x320(因为以横向模式运行应用程序)。 在 iOS 8 (iPhone 4S) 中,返回 CGSize (width=480, height=320) - 正确结果。

iOS 7 不检查横向/纵向模式返回帧,纵向模式返回大小的印象。

谢谢。

【问题讨论】:

    标签: ios objective-c iphone ios7 ios8


    【解决方案1】:

    iOS 8 中的行为发生了变化。

    引用UIScreen 文档

    在 iOS 8 之前,屏幕的边界矩形总是反映相对于纵向向上的屏幕尺寸。将设备旋转到横向或倒置方向不会改变边界。在 iOS 8 及更高版本中,屏幕的 bounds 属性会考虑屏幕的界面方向。此行为意味着纵向设备的边界可能与横向设备的边界不同。依赖于屏幕尺寸的应用可以使用 fixedCoordinateSpace 属性中的对象作为它们必须进行的任何计算的固定参考点。

    【讨论】:

      【解决方案2】:

      是的,iOS 8 的 API 发生了变化。

      是的,它在 iOS8 中取决于方向,而不是错误。您可以查看 WWDC 2014 的第 214 场会议以获取更多信息:“View Controller Advancements in iOS 8”

      演讲中的引述:

      UIScreen 现在是面向界面的:

      [UIScreen bounds] now interface-oriented
      [UIScreen applicationFrame] now interface-oriented
      Status bar frame notifications are interface-oriented
      Keyboard frame notifications are interface-oriented
      

      可能重复查询:Is [UIScreen mainScreen].bounds.size becoming orientation-dependent in iOS8?

      要实现您的目标,请检查 iOS 版本并相应地运行代码:

      How can we programmatically detect which iOS version is device running on?

      希望这会有所帮助。

      【讨论】:

      • 不应该-convertRect:fromWindow:nil继续做正确的事吗?如果是这样,那么作者就不需要编写自己的带有版本检查的小自定义转换代码。只使用预期的内置方法?
      猜你喜欢
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 2014-11-14
      • 1970-01-01
      • 1970-01-01
      • 2012-09-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多