How to hide status bar automatically after load vi

2019-09-09 11:35发布

问题:

guys, I want to hide the status bar in the code. After loaded view, the status bar will show and it will automatically hide after a while. How to do that?

回答1:

You want UIApplication's setStatusBarHidden:withAnimation:

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];

See the docs.



回答2:

Haven't tested it and there might be a better way but if you put the following in your load view function:

[self performSelector:@selector(hideNavBar) withObject:nil afterDelay:0.0];

and then have this function

-(void) hideNavBar {
    if (self.navigationController.navigationBar.hidden == NO)
    {
        [self.navigationController setNavigationBarHidden:YES animated:YES];
    }
}

You might have to hide the navigation bar in a view animation block. but some combination should work

Check out link



回答3:

You could simply do it in you AppDelegate, when applicationDidBecommeActive ("After loaded view"). Set hide status after 400ms, with UIView animation block and calculate your root view controller's navigation bar

// AppDelegate.m

#import "AppDelegate.h"
#import "SomeViewController.h"

@interface AppDelegate ()
@property (nonatomic, strong) SomeViewController *someViewController;
@end

@implementation AppDelegate

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    UINavigationBar *navBar = self.someViewController.navigationController.navigationBar;
    if (![[UIApplication sharedApplication] isStatusBarHidden]) {
       [[UIApplication sharedApplication] setStatusBarHidden:YES
                                               withAnimation:UIStatusBarAnimationSlide];
       [UIView animateWithDuration:0.4
                        animations:^{
                            navBar.frame = CGRectMake(navBar.frame.origin.x, 0, navBar.frame.size.width, navBar.frame.size.height);
                     } completion:nil];
    }
}

@end

that's it, "After loaded view (didBecomeActive), the status bar will show and it will automatically hide after a while (400ms)"



回答4:

You have to select your project and select Hide during application launch inside the header General, section Deployment Info like this:

And inside the info.plist set the View controller-based status bar to NO: