How do I get the navigation bar in a UINavigationController to update its position when the status bar is hidden?

前端 未结 4 1914
长发绾君心
长发绾君心 2020-12-05 14:35

I have a UINavigationController with a visible Navigation Bar. I have one particular UIViewController which I\'d like to hide the status bar when p

4条回答
  •  遥遥无期
    2020-12-05 15:24

    In your root view controller (where you want to show the status bar):

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    
        [[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];;
    }
    

    In the view controller you push on the stack (where you want to hide the status bar):

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    
        [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];;
    }
    

    Edit:

    I realize now you want to hide the status bar. Got them mixed up since you were showing/hiding the nav bar in the code you posted. My mistake. It's essentially the same code, anyway:

    In your root view controller (where you want to show the status bar):

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    
        [[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
    }
    

    In the view controller you push on the stack (where you want to hide the status bar):

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    
        [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
    }
    

    I just tested this with an existing project and it worked.

提交回复
热议问题