When implementing a container view controller, override the childViewControllerForHomeIndicatorAutoHidden () method if you want one of your child's controllers to determine whether to display a visual indicator. If you do this, the system will call the prefersHomeIndicatorAutoHidden () method of the returned view controller. If the method returns nil, the system calls the prefersHomeIndicatorAutoHidden () method of the current view controller
So, if you use childViewController , then you need to implement childViewControllerForHomeIndicatorAutoHidden as -
Swift
extension UINavigationController { open override func childViewControllerForHomeIndicatorAutoHidden() -> UIViewController? { return DemoViewController.loadFromNib() } } //DemoViewController is childViewController class DemoViewController: UIViewController { static func loadFromNib() -> DemoViewController{ let storyBoardInst = UIStoryboard(name: "Main", bundle: nil) return storyBoardInst.instantiateViewController(withIdentifier: "DemoViewController") as! DemoViewController } override func prefersHomeIndicatorAutoHidden() -> Bool { return true } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(true) view.backgroundColor = .red if
Goal C -
@interface UINavigationController(custom) @end @implementation UINavigationController(custom) -(UIViewController *)childViewControllerForHomeIndicatorAutoHidden{ return [self.storyboard instantiateViewControllerWithIdentifier:@"DemoViewController"]; } @end //DemoViewController is childViewController @interface DemoViewController () @end @implementation DemoViewController -(BOOL)prefersHomeIndicatorAutoHidden{ return true; } -(void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:YES]; self.view.backgroundColor = [UIColor redColor]; //Notifies UIKit that your view controller updated its preference regarding the visual indicator if (@available(iOS 11.0, *)) { [self setNeedsUpdateOfHomeIndicatorAutoHidden]; } }
Output -

source share