1

I have an application that I want to go full screen (hiding the status bar) on iPhones that do not have a notch, but stick to the safe area (keeping the status bar visible) on iPhones that have a notch, like the iPhone X.

I cannot just restrict my application to the safe area on all devices, since the safe area includes the status bar on iPhones that do not have a notch.

The approaches I can think of are:

  • Checking the device model, or
  • Looking at the safe area insets for the main UIWindow and trying to infer something from the actual values (e.g. "if top inset is >22, then it has a notch")

None of the above is very clean, not future-proof.

Grodriguez
  • 21,501
  • 10
  • 63
  • 107
  • As of now, doing the calculation on the basis of status bar height and top inset area is the only way to determine the notch in a more accurate way. Because if there is a notch then definitely, the status bar will have a bigger height then normal. In the future, the more chances are that Apple will remove the notch to make more room. In this, the status bar height will be back to normal for sure because there will be no reason to make it bigger. What you say? – Shubham Feb 21 '19 at 13:23
  • It is very unlikely that you will be able to build a future-proof version of this. No one expected the notch before it showed up. We won't expect the next twist either. How will your system deal with a second notch on the bottom edge, or a differently-shaped notch, or extra insets from the side? In my experience, follow Apple's advice as closely as you can (using Storyboards for example, which usually auto-adapt better than custom code). In this case, their advice is likely "don't adapt this way." But accept that you'll have to update UI for new devices, & design so that's as easy as possible. – Rob Napier Feb 21 '19 at 14:09
  • (BTW, when I say Apple's advice is "don't adapt this way," you might say "but Apple violates that kind of advice all the time." And the answer is, "yes, they do." Been screaming about that since at least when iTunes broke all the rules about how window frames are supposed to work. Yeah. Apple breaks their rules all the time…) All that said, your "top inset > 22" is probably the best answer not in that it means there's a notch, but that there is enough room for the information (or as close as you can get to answering that actual question). – Rob Napier Feb 21 '19 at 14:16

1 Answers1

0

I was not able to find any "future-proof" way to do this, so I am finally relying on the safe area insets.

One important note, though, is that this should not be done by checking the top inset alone, as the top inset may vary, for example, when the in-call status bar is being shown. It is better to check either the bottom inset or both bottom and top.

Grodriguez
  • 21,501
  • 10
  • 63
  • 107