当打印iPhone 6+模拟器的屏幕高度时,我得到了2208,正如预期的那样。然而,当我在实际的iPhone 6+上测试时,我得到了1920。很困惑哪一个是对的。这是我使用的代码:

func test() {
    if UIDevice().userInterfaceIdiom == .phone {
        switch UIScreen.main.nativeBounds.height {
        case 1136:
            print("iPhone 5 or 5S or 5C")
        case 1334:
            print("iPhone 6/6S/7/8")
        case 2208:
            print("iPhone 6+/6S+/7+/8+")
        case 2436:
            print("iPhone X")
        default:
            print("unknown")
        }
    }
}

最佳答案

问题是,所有plus设备都会进行下采样,因此要解决此问题,您需要测试两种不同的分辨率,一种用于模拟器2208,另一种用于实际设备1920,如您在answer中所见:

case 1920, 2208:

关于ios - iPhone 6+屏幕尺寸困惑,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48315073/

10-10 19:43
查看更多