Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect iPhone X home indicator?

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.

like image 738
Ser Pounce Avatar asked Dec 07 '22 17:12

Ser Pounce


1 Answers

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.

like image 157
Jordan H Avatar answered Dec 28 '22 01:12

Jordan H