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
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.
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.
Swift version of @Beniamin's answer:
extension UINavigationController {
open override var childForHomeIndicatorAutoHidden: UIViewController? {
return topViewController
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With