The new iPhone X has gotten rid of the home button and replaced it with a "home indicator" at the very bottom that allows the user to swipe up to get back to the home screen.
My question is, how do we detect if this home indicator is on the screen? I want to do something like:
if (!notfullScreen)
{
if (swipeBarExists)
{
viewHeight -= swipeBarHeight;
}
}
I checked in [UIApplication sharedApplication]
and found nothing. Basically I don't really know what to call this thing and am having trouble finding an answer.
You can utilize safeAreaInsets.bottom
, defined for UIView
to get the amount of space you should inset your content to ensure it doesn’t underlap the home indicator (or other elements). Note that this value may change, for example, when you rotate to landscape on iPhone it shrinks. To be notified when this occurs, implement safeAreaInsetsDidChange
in your view controller. You can also utilize the safeAreaLayoutGuide
with Auto Layout.
So, if you have a full screen view, you could check like so:
override func viewSafeAreaInsetsDidChange() {
super.viewSafeAreaInsetsDidChange()
if view.safeAreaInsets.bottom > 0 {
//home indicator
} else {
//no home indicator
}
}
Note that there is no API to get the height of just the home indicator bar itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With