【问题标题】:iOS 8.x alternative to detect iPhone 5s, using [UIScreen mainScreen].bounds.size.height == 568.0iOS 8.x 替代检测 iPhone 5s,使用 [UIScreen mainScreen].bounds.size.height == 568.0
【发布时间】:2015-01-07 17:38:30
【问题描述】:

在 iOS 8 之前的 iOS 版本中,要检查设备是否为 iPhone 5/iPhone 5s,检查 [UIScreen mainScreen].bounds.size.height == 568.0 就足够了。但在 iOS 8.x 及以后的版本中,此检查可能会失败,因为边界现在取决于方向。我需要一个解决方案来识别 iPhone 5s、6 和 6+ 设备,而无需检查 iOS 版本。

【问题讨论】:

    标签: objective-c ios8 iphone-5 bounds mainscreen


    【解决方案1】:

    你可以检查一下

    [UIScreen mainScreen].bounds.size.height == 568.0   
    

    [UIScreen mainScreen].scale 识别 iPhone 6 和 6+

    请注意,如果应用程序在“缩放”模式下工作,这将不起作用。
    在这种情况下,iPhone 6 和 6+ 将提供 scale 2.0

    【讨论】:

    • 您能否解释一下 iPhone 6 和 6+ 的缩放模式是什么?请给出一个基本的想法。我是新手。
    • @RashmiRanjanmallick 如果您没有为 iPhone 6 / 6+ 指定 Splash 图像(例如在 ImageAssets 中),应用程序将开始在缩放模式下工作,并且两个 iPhone 上的屏幕边界均为 320 x 568 6、6+
    • 非常感谢朋友!!!我真的不知道我应该添加多大尺寸的闪屏来支持 iPhone 6 和 6+。有什么帮助吗?
    • iPhone 6 - 750 x 1334 像素,iPhone 6+ 1242 x 2208 像素
    • 再次感谢。因此,只有添加上述两个启动画面才能为我完成工作。我对么?请确认。
    【解决方案2】:

    我能够使用以下宏检测设备。如果您想识别设备以对视图执行一些更新(例如在方向更改时更新框架),这将很有用。如果您确实想要设备型号/品牌,请改用此链接 (ios iphone get device model and make?)。

    #define IS_IPHONE       ((int)(MAX([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)) == 480)
    #define IS_IPHONE5      ((int)(MAX([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)) == 568)
    #define IS_IPHONE6      ((int)(MAX([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)) == 667)
    #define IS_IPHONE6PLUS  ((int)(MAX([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)) == 736)
    

    【讨论】:

    • 如果应用程序处于“缩放”模式(6 或 6+ 时缺少启动画面),这将不起作用
    • @l0gg3r:你说得对,在缩放模式下会失败。在缩放模式下 iPhone5 检查也适用于 iPhone6 和 iPhone6+。所以我会更新答案以涵盖这一点。
    • @l0gg3r:我说它对我有用是因为,我的要求是识别设备,在方向更新时更新视图的框架。我的应用程序支持两种新分辨率,所以不用担心缩放模式。此外,如果应用程序在缩放模式下运行,我们无需担心;系统会处理这种情况。为 iPhone 5 分辨率设置视图框架,系统将缩放/缩放以适应新分辨率。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-17
    • 2017-01-25
    • 2012-09-06
    • 2014-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多