Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 7 How to animate StatusBarStyle from DefaultContent to LightContent

I am trying to transition the status bar style from UIStatusBarStyleDefaultContent to UIStatusBarStyleLightContent using a UIView animation, however, the style just switches with no fade animation. I figured that setting the style using the following would work:

[UIView animateWithDuration:1.0
                      delay:0.0
                    options:UIViewAnimationOptionCurveEaseInOut
                 animations:^{
                     [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
                     [self.view layoutIfNeeded];
                 } completion:nil];

I am not sure how to get what I want to happen. Basically, my content changes from dark to light so I need to change the status bar color. By default it doesn't work the way I want. Any help is much appreciated.

Thanks!

like image 316
crizzwald Avatar asked Mar 22 '23 00:03

crizzwald


2 Answers

This is how it's done.

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

Here is the UIApplication Class Reference

Hopefully this will help someone.

like image 66
crizzwald Avatar answered Apr 08 '23 14:04

crizzwald


I suspect that you can't do what you're trying to do.

The docs say that the animation when you call setStatusBarStyle is a slide animation:

statusBarStyle The current style of the status bar.

@property(nonatomic) UIStatusBarStyle statusBarStyle Discussion The value of the property is a UIStatusBarStyle constant that indicates the style of status. The default style is UIStatusBarStyleDefault. The animation slides the status bar out for the old orientation and slides it in for the new orientation.

like image 40
Duncan C Avatar answered Apr 08 '23 15:04

Duncan C