简体   繁体   中英

hide home indicator for iPhone X

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

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

and also

-(BOOL)prefersHomeIndicatorAutoHidden{
   return YES;
}

but no luck. Does anyone have any idea?

When implementing a container view controller, override childViewControllerForHomeIndicatorAutoHidden() method if you want one your child view controllers to determine whether to display the visual indicator. If you do, the system calls 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 are using childViewController then 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()
        }
    }
}

Objective 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 YES;
}
-(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 -

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM