Hide home indicator for iPhone X

I have an iOS application with a video player, when the video is playing (landscape, full screen), I would like to hide the home indicator on the iPhone X. I tried

if (@available(iOS 11.0, *)) { [self setNeedsUpdateOfHomeIndicatorAutoHidden]; } 

and

 -(BOOL)prefersHomeIndicatorAutoHidden{ return YES; } 

but no luck. Somebody knows?

+5
source share
1 answer

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 #available(iOS 11.0, *) { //Notifies UIKit that your view controller updated its preference regarding the visual indicator setNeedsUpdateOfHomeIndicatorAutoHidden() } } } 

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 -

enter image description here

+2
source

Source: https://habr.com/ru/post/1273419/


All Articles