Reputation: 69
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
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