Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

troop231

macrumors 603
Original poster
Jan 20, 2010
5,826
561
All is fine when I hide both my navigationBar and my statusBar, but when I want to show both again, I end up with this 20px white space under the navigationBar, and the navigationBar is also 20px too high under the returned statusBar. See screenshot below after the code:

Code I'm using:
Code:
- (void)toggleNavBar:(UITapGestureRecognizer *)gesture 
{
    BOOL barsHidden = self.navigationController.navigationBar.hidden;
    [self.navigationController setNavigationBarHidden:!barsHidden animated:YES];
    
    if (!barsHidden) 
    {
        [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
    }
    
    else if (barsHidden) 
    {
        [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
    }
}

2yPhR.png



I appreciate any help.

Thank you in advance!
 
Last edited:
Have you tried adjusting the frame of the navigation bar (not saying it's the "correct" solution, but it's probably the one I'd go with...)
 
Maybe you should show navBar after showing status bar. If navigation calculates its position at the moment when status bar is hidden things may not work as expected.
 
Maybe you should show navBar after showing status bar. If navigation calculates its position at the moment when status bar is hidden things may not work as expected.

Thank you! this is what worked for me :)

Code:
- (void)toggleNavBar:(UITapGestureRecognizer *)gesture 
{
    BOOL barsHidden = self.navigationController.navigationBar.hidden;
    
    if (!barsHidden) 
    {
        [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
    }
    
    else if (barsHidden) 
    {
        [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
    }
    
    [self.navigationController setNavigationBarHidden:!barsHidden animated:YES];
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.