【问题标题】:Altenative [UIScreen mainScreen].nativeScale for iOS 7 support?iOS 7 支持的替代 [UIScreen mainScreen].nativeScale?
【发布时间】:2014-10-18 14:14:05
【问题描述】:

有人知道以下代码的替代方法吗?我想在我的应用程序中支持 iOS 7 及更低版本,而 .nativeScale 不适用于这些固件。我在互联网上找不到解决方案,这就是我在这里问的原因。 (通常让屏幕边界检查 568 的高度不适用于 iPhone 6+)

我所指的代码:

CGRect screenBounds = [[UIScreen mainScreen] bounds];
if ([UIScreen mainScreen].nativeScale > 2.1) {
//6 plus

} else if (screenBounds.size.height == 568) {
//4 inch / iPhone 6 code

} else {
//3.5 inch code

}

提前致谢

【问题讨论】:

  • 你的目标是什么?没有 iPhone 6/6+ 将运行 iOS 7。为什么你声称 568 的高度等同于 iPhone 6?这是 iPhone 5 的高度,而不是 iPhone 6(除非您的应用正在缩放)。
  • 我的目标是尽可能支持 iOS 7 和 6。现在我的应用程序崩溃(在我的 iPhone 4S - 7.1.1 上)因为 .nativeScale 在 iOS 8 以下不兼容。我的意思正是你所说的,568 不适用于 iPhone 6+,这就是我必须实施的原因第二种方法(.nativeScale)
  • 怎么样:if ([[UIScreen mainScreen] respondsToSelector:@selector(nativeScale)]) { .. ios 8 code .. }
  • 您的应用程序是否完全支持 iPhone 6 和 6+ 的原生分辨率(换句话说,您是否有正确的 iPhone 6/6+ 启动图像)?还是您的应用仅支持 3.5 和 4" 设备并且应用在 iPhone 6 和 6+ 上进行了缩放?如果是前者,请检查尺寸是否合适。如果是后者,您为什么需要知道应用是否在iPhone 6 或 6+?没关系。
  • 我已经修好了。不管怎么说,还是要谢谢你。如果您有兴趣,我会发布解决方案

标签: ios objective-c iphone xcode adjustment


【解决方案1】:

所以我所做的是: 首先,我按以下顺序使用方法:

if ([UIScreen mainScreen].nativeScale > 2.1) {
    //6 plus

} else if (screenBounds.size.height == 568) {
    //4 inch code

} else {
//3.5 inch code

}

然后我想既然计算机停止运行if else 语句,一旦他找到一个真正的语句,我只是将顺序重新排列为以下:

if (screenBounds.size.height == 480) {
//3.5 inch code

} else if ([UIScreen mainScreen].nativeScale > 2.1) {
    //6 plus

} else if (screenBounds.size.height == 568) {
    //4 inch code

}

这支持 iOS 7 或更低版本的 iPhone 4S。在 iPhone 5 / 5S 上它仍然会崩溃。所以最后我把它改成了下面这样:

if ([[UIScreen mainScreen] respondsToSelector:@selector(nativeScale)]) {
//checks if device is running on iOS 8, skips if not
    NSLog(@"iOS 8 device");

    if (screenBounds.size.height == 480) {
        //3.5 inch code
        NSLog(@"iPhone 4S detected");

    } else if ([UIScreen mainScreen].nativeScale > 2.1) {
        //6 plus
        NSLog(@"iPhone 6 plus detected");

    } else if (screenBounds.size.height == 568) {
        //4 inch code
        NSLog(@"iPhone 5 / 5S / 6 detected");
    }
} else if (screenBounds.size.height == 480) {
    //checks if device is tunning iOS 7 or below if not iOS 8
    NSLog(@"iOS 7- device");
    NSLog(@"iPhone 4S detected");
//3.5 inch code

} else if (screenBounds.size.height == 568) {
    NSLog(@"iOS 7- device");
    NSLog(@"iPhone 5 / 5S / 6 detected");
    //4 inch code

}

它现在应该可以在任何 iOS 7 和 iOS 8 设备上完全运行!

【讨论】:

    猜你喜欢
    • 2014-11-17
    • 2015-01-07
    • 1970-01-01
    • 2017-01-25
    • 1970-01-01
    • 1970-01-01
    • 2013-07-02
    • 1970-01-01
    • 2012-09-06
    相关资源
    最近更新 更多