Resolved Hiding/Showing Status Bar & Nav Bar issue.

Discussion in 'iOS Programming' started by troop231, Jul 16, 2012.

  1. troop231, Jul 16, 2012
    Last edited: Jul 17, 2012

    troop231 macrumors 603

    Joined:
    Jan 20, 2010
    #1
    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];
        }
    }
    [​IMG]


    I appreciate any help.

    Thank you in advance!
     
  2. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    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...)
     
  3. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #3
    I think the issue is your XIB ;)
    Did you add an status bar there? (otherwise the XML of the XIB gets confused, and it starts at 0 pixels instead of 20 (on a Window base).
     
  4. idelovski macrumors regular

    Joined:
    Sep 11, 2008
    #4
    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.
     
  5. troop231 thread starter macrumors 603

    Joined:
    Jan 20, 2010
    #5
    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];
    }
     

Share This Page