9

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

BlackWolf
  • 5,239
  • 5
  • 33
  • 60

3 Answers3

9

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.

  • worked for me, but I had to use `self.topViewController` – BlackWolf Oct 18 '17 at 07:04
  • 1
    `-(BOOL)prefersHomeIndicatorAutoHidden { return self.shouldHideHomeIndicator;//YES } -(UIViewController *)childViewControllerForHomeIndicatorAutoHidden { return self; }` @BeniaminSarkisian I have added this in my Objective C code. but not working – Vinu David Jose Nov 06 '17 at 10:10
  • @S.Wei No. I have implemented that methods, but not working – Vinu David Jose Nov 16 '17 at 11:41
3

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.

Forte Zhu
  • 742
  • 3
  • 12
  • 33
  • while this is true, I know of no known circumstance where the system will currently ignore this setting during normal app use. In particular, I am using it in a very similar context to apple's own photos app. The problem was indeed, as mentioned above, that another method needs to be implemented when inside a navigation controller. – BlackWolf Nov 06 '17 at 17:11
2

Swift version of @Beniamin's answer:

extension UINavigationController {
    open override var childForHomeIndicatorAutoHidden: UIViewController? {
        return topViewController
    }
}
unixb0y
  • 979
  • 1
  • 10
  • 39