goat
goat

Reputation: 69

iPhone 6+ screen dimension confusion

When printing the screen height of the iPhone 6+ simulator I get 2208, as expected. However when I test on an actual iPhone 6+ I get 1920. Very confused about which one is right. Here is the code I'm using:

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")
        }
    }
}

Upvotes: 0

Views: 82

Answers (2)

Jaydeep Vora
Jaydeep Vora

Reputation: 6213

Videos, OpenGL, and other things based on CALayers that deal with pixels will deal with the real 1920x1080 frame buffer on device (or 2208x1242 on sim). Things dealing with points in UIKit will be deal with the 2208x1242 (x3) bounds and get scaled as appropriate on device.

The simulator does not have access to the same hardware that is doing the scaling on device and there's not really much of a benefit to simulating it in software as they'd produce different results than the hardware. Thus it makes sense to set the nativeBounds of a simulated device's main screen to the bounds of the physical device's main screen.

iOS 8 added API to UIScreen (nativeScale and nativeBounds) to let a developer determine the resolution of the CADisplay corresponding to the UIScreen.

Upvotes: 0

Leo Dabus
Leo Dabus

Reputation: 236360

The problem is that all plus devices they do a downsampling so to fix this issue you need to test two different resolutions, one for the simulator 2208 and one for the real devices 1920 as you can see in this answer:

case 1920, 2208:

Upvotes: 1

Related Questions