safeAreaInsets Wrong on New iPad Without Status Bar

If I create a new single view project and add the following code to ViewController.m


-(void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    NSLog(@"%@", NSStringFromUIEdgeInsets(UIApplication.sharedApplication.windows[0].safeAreaInsets));
}


I get the following results with the new iPad 11" and 3rd gen 12.9":


With Status Bar:

{24, 0, 20, 0}


Without Staus Bar:

{0, 0, 20, 0}


Why is the top inset 0 instead of 20 when there is no status bar?


I remove the status bar by setting

UIStatusBarHidden=YES
and
UIViewControllerBasedStatusBarAppearance=NO
in the info.plist. The results I get on the iPhones always correctly account for the curved edges.

Accepted Reply

This is expected behavior on an iPad.


The non-zero top inset on the iPhone is the exceptional case —it's there because the iPhone has "ears", not because of the iPhone's status bar. Since the new iPads don't have ears, their safe area always goes all the way to the top when there's no status bar.


Note that the safe area doesn't directly try to avoid the rounded corners. The top inset avoids the ears and the status bar; the bottom inset avoids the home indicator. If you're actually trying to avoid the rounded corners, check whether the bottom inset is non-zero (to know whether the device has rounded corners), then use a standard horizontal inset (20 points) for UI elements near the top or bottom of the screen.

Replies

This is expected behavior on an iPad.


The non-zero top inset on the iPhone is the exceptional case —it's there because the iPhone has "ears", not because of the iPhone's status bar. Since the new iPads don't have ears, their safe area always goes all the way to the top when there's no status bar.


Note that the safe area doesn't directly try to avoid the rounded corners. The top inset avoids the ears and the status bar; the bottom inset avoids the home indicator. If you're actually trying to avoid the rounded corners, check whether the bottom inset is non-zero (to know whether the device has rounded corners), then use a standard horizontal inset (20 points) for UI elements near the top or bottom of the screen.

Thank you. I had assmed the safeAreaInsets accounted for the rounded corners because it seems to for the iphones when in landscape. When the iPhone X is in landscape I get the following results:

{0, 44, 21, 44}

Why is there a 44 on both the left and right when there is only ears on one side?

The left and right are symmetrical (I presume) to center the placement of the content, so that it doesn't look different depending on whether the ears face left or face right. That is, if the phone is in landscape, the screen looks the same no matter which way up you hold the phone (except that the notch is only on one of the side, of course).


This might matter, for example, for a game where there are touch controls near the corners. You really wouldn't want the controls shimmying left or right depending on which way you were holding the phone in landscape.

I suppose. I wish there was more consistency. Thanks for your help!