views:

38

answers:

1

I'd like to show and hide the statusBar and the navigationBar simultaneously using a slide effect.

This is how I tried:

[[UIApplication sharedApplication] setStatusBarHidden:hide withAnimation:UIStatusBarAnimationSlide];
[self.navigationController setNavigationBarHidden:hide animated:animated];

However, the duration of both animation is not the same. The status bar animation takes longer. I found no way how to specify the duration of either animation. Did I miss something obvious?

A: 

This isn't much of an answer but it works. So what I did is:


// This method gets called by whatever action you want

- (void) toggleShowStatusNavBars:(id)sender {

    // Assuming you have a ivar called barsHidden

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.4]; // This is IMPORTANT, 0.4s

    self.navigationController.navigationBar.alpha = (barsHidden?1.0:0.0);  

    barsHidden = !barsHidden; 

    [UIView setAnimationDelegate:self];
    [UIView setAnimationWillStartSelector:@selector(setStatusBarHidden)];

    [UIView commitAnimations];
}

- (void) setStatusBarHidden {
    [[UIApplication sharedApplication] setStatusBarHidden:barsHidden animated:YES];
}

This will basically synchronize the start of the animation (since you are calling setStatusBarHidden at the start of the navigation bar animation. The key part is that the status bar animation seems to take 0.4 seconds.

This works for me but if you find a better way, do post here.

Ephraim
You're hiding the navBar using alpha fading. This is easier because in this case you can manipulate the navBar directly. In the sliding case I'm interested in that's not a viable approach since the navigationController also manipulates the content view frame.
Ortwin Gentz