How to hide status bar automatically after load vi

2019-09-09 11:52发布

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?

4条回答
成全新的幸福
2楼-- · 2019-09-09 12:15

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

enter image description here

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

enter image description here

查看更多
冷血范
3楼-- · 2019-09-09 12:16

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楼-- · 2019-09-09 12:22

You want UIApplication's setStatusBarHidden:withAnimation:

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

See the docs.

查看更多
Animai°情兽
5楼-- · 2019-09-09 12:31

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

查看更多
登录 后发表回答