0
votes

I need for the status bar to fade out when the user taps the screen, and I'm wondering if this is possible using Core Animation. I've set the status bar as so:

[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackTranslucent animated: YES];

When I was using UIView animation, and I placed [[UIApplication sharedApplication] setStatusBarHidden:NO]; in the UIView animateWithDuration block, it made it dissolve. However when I'm using core animation, it's not working:

[CATransaction begin];
CABasicAnimation *fader = [CABasicAnimation animationWithKeyPath:@"opacity"];
[fader setDuration:2.0];
[fader setFromValue:[NSNumber numberWithFloat:.75]];
[fader setToValue:[NSNumber numberWithFloat:0]];
[[[[self tabBarController] tabBar]layer]addAnimation: fader forKey:@"BigFade"];

CABasicAnimation *fader2 = [CABasicAnimation animationWithKeyPath:@"opacity"];
[fader2 setDuration:2.0];
[fader2 setFromValue:[NSNumber numberWithFloat:1]];
[fader2 setToValue:[NSNumber numberWithFloat:0]];
[[[[self navigationController] navigationBar]layer]addAnimation: fader2 forKey:@"BigFade2"];

[[UIApplication sharedApplication] setStatusBarHidden:YES];
[CATransaction commit];

Any ideas on how to get this done in Core Animation (I need to use Core Animation instead of UIView animation)?

1

1 Answers

2
votes

You explained that you don't want to use UIViewAnimation, but don't say why. Do you want to have a custom fade animation? Gives us more detail about your motivation. What is wrong in your case with using - (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation? You can pass the constant UIStatusBarAnimationFade for the second argument to get a fade effect.

The problem you will face wanting to do it differently is that there is no official way to access the status bar view.

Nothing in the documentation says that the statusBar is part of the navigationBar. Thus, your code [[self navigationController] navigationBar]layer] ... will not have the effect you hope for.