5

I read the native height of the phone to size my display output, and determine top and bottom keep out areas. This is a tab based app. My display is purely programmatic, it is graphically layed out based on screen dimension only. On the iPhone 12 mini, the display is smaller than it should be. The other iPhone 12 types display correctly.

While testing my new app on various iPhone types in the xcode simulator, they looked correct. But when I put the app on my iPhone 12 mini, the display was smaller than it should be. I learned the simulator returns the value 2436 for native height, but the phone returns the value 2340. This code examines the display and tells me how much to reserve on the top and bottom of the screen by type of phone:

nativeHeight=UIScreen.main.nativeBounds.height
    if nativeHeight==1136 || nativeHeight==1334             // SE,6S,7,8
        {reserveTopPixels=40; reserveBottomPixels=98}
    else if nativeHeight==1792                              // 11, XR
        {reserveTopPixels=88; reserveBottomPixels=198}
    else if nativeHeight==2208                              // 6s+ 7+ 8+
        {reserveTopPixels=54; reserveBottomPixels=146}
    else if nativeHeight==2436 || nativeHeight==2688        // X, XS, 11Pro, 11, Xr
        {reserveTopPixels=132; reserveBottomPixels=260}
    else if nativeHeight==2340 //iPhone 12 mini "downsampled screen"
        {reserveTopPixels=132; reserveBottomPixels=260; nativeHeight = 2436}
    else if nativeHeight==2532                              // 12, 12 pro
        {reserveTopPixels=132; reserveBottomPixels=260}
    else if nativeHeight==2778                              // 12 pro max
        {reserveTopPixels=132; reserveBottomPixels=260}
    else {reserveTopPixels=40; reserveBottomPixels=98}

My correction is to change the value received from the phone, 2340, to a larger value, 2436.

The app displays correctly now on both the simulator and the phone. My question is, is this a reasonable solution, or should I try something else.

zeytin
  • 5,545
  • 4
  • 14
  • 38
user1644002
  • 3,211
  • 3
  • 19
  • 21
  • iPhone 12 Mini display is 2340 x 1080, but standard scale screenshots are 2436 x 1125 (native resolution). Software running on the 12 Mini “sees” the display as 2436 x 1125, but everything is downsampled on-the-fly to 2340 x 1080. 2436 x 1125 is the software interface size of the 12 Mini display. In your code you should use native resolution. – Haris Dec 27 '20 at 00:39
  • Reference: https://daringfireball.net/2020/11/the_iphone_12_mini_and_iphone_12_pro_max https://useyourloaf.com/blog/iphone-12-screen-sizes/ – Haris Dec 27 '20 at 00:39
  • Haris, when I single step the app right on the phone through the phone sizing steps, the phone returns value of 2340. That is why in the code above I had to change the value to 2436. If I use the value returned, 2340, then my display is sized a little to small it doesn't look right. If I use the modified value, as shown above, the display is sized correctly for the screen. – user1644002 Dec 27 '20 at 20:12
  • More succinctly, the phone is supposed to return height of 2436, the simulator returns height of 2436, so code running the simulator displays correctly. BUT the phone actually returns height of 2340, an app reads that and produces a display for that size, but it is runted by the downscaling so it appears smaller than same display on simulator. My code above attempts to work round that issue and I am asking if it is a good workaround. If the phone gets updated and returns the value 2436, my workaround is still good. – user1644002 Dec 29 '20 at 18:33
  • 1
    Maybe this will help you -> https://stackoverflow.com/questions/21668497/uiscreen-mainscreen-bounds-returning-wrong-size – Haris Dec 29 '20 at 18:50
  • I appreciate the four proposed answers, but it looks like I wrote a question that people don't understand. I cannot choose any answer. – user1644002 Jan 03 '21 at 11:18

2 Answers2

1

nativeBounds: CGRect. : provides the bounding rectangle of the physical screen, measured in pixels. And the physical screen for iPhone 12 mini is 1080×2340 pixels

The iPhone 12 mini has a physical screen resolution of 1080 x 2340 pixels (476 ppi). This is lower than the native resolution reported by the operating system (using nativeBounds on UIScreen). I assume this is to maintain compatibility with the resolutions of the 5.8" models (iPhone X/XS/11 Pro).

Reference :

It depends on where you are using this nativeHeight to layout.

Nandish
  • 1,136
  • 9
  • 16
  • 2
    Nandish, the phone is reporting native height of 2340. See code above. – user1644002 Dec 30 '20 at 18:11
  • Nandish, Iam using this native height while drawing my display, it is done programmatically. So it is all proportional to the given size, and when I get the wrong height from the phone,, too short, my display looks wrong (runted a little) – user1644002 Jan 02 '21 at 22:45
0

As you indicated you have problem just for on the iPhone 12 mini simulator. Then Why do you need all checking logic ? Just be sure you working on simulator and catch the iPhone 12 mini and make your adjustment. I think that extension would make sense.

static var isSimulator: Bool {
    return TARGET_OS_SIMULATOR != 0
}

extension UIDevice {
    var modelIdentifier = ""
    modelIdentifier = ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"] ?? ""
    let nativeHeight = UIScreen.main.nativeBounds.height
    if nativeHeight==2340 // your specific case
    {
    reserveTopPixels=132; reserveBottomPixels=260; nativeHeight = 2436
    }
}

Edit

Then If you want certain code to be run only in the iOS simulator either device, you should use this:

func adjust() {
#if targetEnvironment(simulator)
    // we're on the simulator 
    }
#else
    // we're on a device
    }
#endif
}
zeytin
  • 5,545
  • 4
  • 14
  • 38
  • thank you, to me it appears the simulator is working correctly already, it is returning the value of 2436, while the phone returns the lower value of 2340, which I believe is incorrect. Anyway, I need the tightly constructed app display to match between simulator and real item. My workaround does that, but I don't want additional issues due to that workaround. The code shown has to work on all iPhones, or simulator. – user1644002 Jan 02 '21 at 12:58