Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why is my app's display on iPhone12 mini incorrectly sized?

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.

like image 785
user1644002 Avatar asked Nov 07 '22 03:11

user1644002


1 Answers

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 :

  • https://hacknicity.medium.com/how-ios-apps-adapt-to-the-various-iphone-12-screen-sizes-e45c021e1b8b
  • https://useyourloaf.com/blog/iphone-12-screen-sizes/

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

like image 189
Nandish Avatar answered Nov 15 '22 11:11

Nandish