Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 703
wes. i Avatar asked Nov 16 '17 05:11

wes. i


People also ask

How do I hide the home bar?

Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.

Can you have a secret Home Screen on iPhone?

Press and hold on a blank space on your Home Screen. Once the apps start wiggling, tap on the Home Screen dots near the bottom of the screen. You'll see an array of your Home Screen pages. Locate the hidden page, which you'll notice will not have a check mark in the bubble below it.


1 Answers

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 -

enter image description here

like image 76
Jack Avatar answered Oct 20 '22 06:10

Jack