Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prefersHomeIndicatorAutoHidden not working on iPhone X

I am currently updating one of my apps to iPhone X and tried to hide the home indicator on a fullscreen viewcontroller showing an image using:

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

This method seems to do nothing, though. It is never called and the home indicator is never hidden, even after a while of inactivity. The simulator does seem to support this since the Photos app does hide the home indicator.

Is there some other flag that needs to be set to make this work? I tried it in multiple view controllers and none of them show the correct behaviour.

I also tried to add

if #available(iOS 11.0, *) {
    self.setNeedsUpdateOfHomeIndicatorAutoHidden()
}

to my viewDidLoad() but to no avail

like image 531
BlackWolf Avatar asked Oct 13 '17 12:10

BlackWolf


Video Answer


3 Answers

If you show your UIViewController in UINavigationController, you have to override childViewControllerForHomeIndicatorAutoHidden() function:

extension UINavigationController {
    open override func childViewControllerForHomeIndicatorAutoHidden() -> UIViewController? {
        return topViewController
    }
}

Or if you show your UIViewController like subview of parent view controller, you also have to override this function and return child view controller.

like image 64
Beniamin Sarkisian Avatar answered Oct 23 '22 01:10

Beniamin Sarkisian


As per developer guide for prefersHomeIndicatorAutoHidden its clear that,

The system takes your preference into account, but returning YES is no guarantee that the indicator will be hidden.

This method is only helpful if any of the objects are overlapping with the home indicator.

FYI, the home indicator will hide only after a couple of seconds, but it will reappear as soon as the user touches the screen.

like image 35
Forte Zhu Avatar answered Oct 23 '22 03:10

Forte Zhu


Swift version of @Beniamin's answer:

extension UINavigationController {
    open override var childForHomeIndicatorAutoHidden: UIViewController? {
        return topViewController
    }
}
like image 36
unixb0y Avatar answered Oct 23 '22 03:10

unixb0y