4

I have an app where I have a button that fades the screen to black. I want to have the status bar fade to black also, so I'm using the following code:

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];

Is it possible for me to set the duration of the fade? If that's not doable, is it possible to get the official fade duration (like using UIKeyboardAnimationDurationUserInfoKey to get the keyboard slide duration).


Well I didn't get anything back from anyone, but I think I should at least share my hack. After some experimentation, I settled on fade out is 1 second and fade in is 0.25 seconds.

- (IBAction)fadeToBlack:(id)sender
{
    UIView *view = [[[UIView alloc] initWithFrame:self.view.window.frame] autorelease];
    view.backgroundColor = [UIColor blackColor];
    view.alpha = 0.0;
    [self.view.window addSubview:view];

    // NOTE: Fading the black view at the same rate as the status bar. Duration is just a guess.
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
    [UIView animateWithDuration:1.0 animations:^{
        view.alpha = 1.0;
    } completion:^(BOOL finished) {
        [view addGestureRecognizer:self.dismissViewGesture];
    }];
}

- (void)dismissViewWithGesture:(UIGestureRecognizer *)gesture
{
    UIView *view = gesture.view;
    [view removeGestureRecognizer:gesture];

    // NOTE: Fading the black view at the same rate as the status bar. Duration is just a guess.
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
    [UIView animateWithDuration:0.25 animations:^{
        view.alpha = 0.0;
    } completion:^(BOOL finished) {
        [view removeFromSuperview];
    }];
}
Jeffery Thomas
  • 42,202
  • 8
  • 92
  • 117

1 Answers1

0

I had the same issue and my values are 0.5 for hiding and 0.2 for showing the navigation bar together with the status bar. At least for iOS 6.1/iOS Simulator those values are matching the reality much better.

Christoph
  • 1,525
  • 1
  • 16
  • 27