BlackWolf
BlackWolf

Reputation: 5599

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

Upvotes: 9

Views: 8271

Answers (3)

unixb0y
unixb0y

Reputation: 1048

Swift version of @Beniamin's answer:

extension UINavigationController {
    open override var childForHomeIndicatorAutoHidden: UIViewController? {
        return topViewController
    }
}

Upvotes: 2

Forte Zhu
Forte Zhu

Reputation: 762

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.

Upvotes: 3

Beniamin Sarkisian
Beniamin Sarkisian

Reputation: 121

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.

Upvotes: 9

Related Questions