How to hide status bar automatically after load view

旧巷老猫 提交于 2019-12-11 19:59:59

问题


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:



来源:https://stackoverflow.com/questions/11372423/how-to-hide-status-bar-automatically-after-load-view

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!