【问题标题】:How to detect the iPad pro running in the simulator?如何检测模拟器中运行的 iPad pro?
【发布时间】:2016-02-28 08:16:16
【问题描述】:

我发现了很多关于设备检测和屏幕尺寸的帖子。 但这些都不适用于模拟器。

模拟器设备类型通常返回 x86_64。

屏幕尺寸[UIScreen mainScreen].bounds.size.height返回1024。

当我需要调整绘图代码时,我有一个场景,而尺寸类不适合。

我被难住了。

【问题讨论】:

    标签: ios ipad cocoa-touch ios-simulator


    【解决方案1】:

    尽管我认为您不应该手动执行此操作,但这里有一些选项。

    首先,您可以将边界乘以比例:

    CGSize size = [UIScreen mainScreen].bounds.size;
    CGFloat scale = [UIScreen mainScreen].scale;
    CGSize realSize = CGSizeMake(size.width * scale, size.height * scale);
    

    或者从 iOS 8 开始,您实际上可以更轻松地做到这一点:

    CGSize realSize2 = [UIScreen mainScreen].nativeBounds.size;
    

    根据documentation,第二种方式会忽略方向,因此可能更容易检查。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2015-12-06
      • 2017-03-04
      • 2011-02-28
      • 1970-01-01
      • 2012-06-21
      • 2018-06-29
      • 2016-10-11
      • 2020-01-06
      • 2016-02-06
      相关资源
      最近更新 更多