iosiphoneuiviewcontrolleriphone-xhome-button

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


Solution

  • 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.