Vlad
Vlad

Reputation: 5927

iPhone X hide home indicator on view controller

I have a view controller that takes up the whole screen from top to bottom. I would like to hide the home bar indicator on the bottom of the screen on iPhone X devices.

How can I do this in iOS 11?

Upvotes: 57

Views: 31424

Answers (7)

Truong Ha
Truong Ha

Reputation: 1

Someone has a problem with

override var preferredScreenEdgesDeferringSystemGestures: UIRectEdge {
    return [.all]
}

You should try this code below, it works for me:

override func preferredScreenEdgesDeferringSystemGestures() -> UIRectEdge {
    return [.all]
}

Upvotes: 0

absmiths
absmiths

Reputation: 1174

There is another alternative. If you are looking for the behavior where the indicator dims, then when the user swipes up it activates, and when they swipe up again the home action is invoked (I.E., two swipes are needed to invoke), then the answer is here: iPhone X home indicator behavior. The short of it is to override on your UIViewController:

override var preferredScreenEdgesDeferringSystemGestures: UIRectEdge {
    return UIRectEdge.bottom
}

prefersHomeIndicatorAutoHidden only hides the indicator, but will not suppress the gesture.

And you will get what you want (If I understand your comments correctly - your question and the selected answer seem to imply the other answer).

Upvotes: 30

Mycroft Canner
Mycroft Canner

Reputation: 1997

I tried to set it and return true only when I am in full-screen :

override var prefersHomeIndicatorAutoHidden: Bool { isNavigationBarAndTabBarHidden }

but it doesn't seem to work... isNavigationBarAndTabBarHidden is a custom variable tied to my fullscreen extension.

Edit: We need to call setNeedsUpdateOfHomeIndicatorAutoHidden every time we update prefersHomeIndicatorAutoHidden's value.

    var isNavigationBarAndTabBarHidden = false {
        didSet {
            setNeedsUpdateOfHomeIndicatorAutoHidden()
        }
    }

Upvotes: 4

glyvox
glyvox

Reputation: 58049

You should override prefersHomeIndicatorAutoHidden in your view controller to achieve that:

override var prefersHomeIndicatorAutoHidden: Bool {
    return true
}

Upvotes: 89

DawnSong
DawnSong

Reputation: 5162

If your window?.rootViewController is a UITabBarController or UINavigationController, just inherit it and add two function as follows,

override var prefersHomeIndicatorAutoHidden: Bool {
    return true
}

//@available(iOS 11, *)
override var childViewControllerForHomeIndicatorAutoHidden: UIViewController? {
    return nil
}

Upvotes: 6

pierreafranck
pierreafranck

Reputation: 443

override func  prefersHomeIndicatorAutoHidden() -> Bool {
    return true
}

I suppose you can add this method in your AppDelegate for hide home indicator on all of your ViewControllers.

enter image description here

Upvotes: 1

DrMickeyLauer
DrMickeyLauer

Reputation: 4674

Implement -(BOOL)prefersHomeIndicatorAutoHidden in your UIViewController and return YES.

Read more https://developer.apple.com/documentation/uikit/uiviewcontroller/2887510-prefershomeindicatorautohidden.

Upvotes: 3

Related Questions