0

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")
        }
    }
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
goat
  • 69
  • 1
  • 11
  • See https://stackoverflow.com/questions/25755443/iphone-6-plus-resolution-confusion-xcode-or-apples-website-for-development – rmaddy Jan 18 '18 at 06:48

2 Answers2

1

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:
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571
  • So, in deployment, all plus size iPhones will use the 1920 height? The 2208 figure is only for plus simulators? What's the point of that? – goat Jan 18 '18 at 07:42
  • This is just how it works. 2208 is the render size and 1920 is the actual number of physical pixels. So in the simulator it just displays it at render size but in the real device it needs downsample the image to be able to display it. – Leo Dabus Jan 18 '18 at 13:49
0

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.

Jaydeep Vora
  • 6,085
  • 1
  • 22
  • 40