Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide status bar with animation in iOS 7?

Since iOS 7 rolled out, I can't show or hide status bar with animation just like in iOS 6. For now I use NSTimer to control it when to hide.

here is my code:

- (void)hideStatusBar{
    _isStatusBarHidden=YES;
    [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
}
- (void)showStatusBar{
_isStatusBarHidden=NO;
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
}
    //===================
 _controlVisibilityTimer = [[NSTimer scheduledTimerWithTimeInterval:4 target:self selector:@selector(hideStatusBar:) userInfo:nil repeats:NO] retain];

But unfortunately the way of status bar hiding seems a little bit rough, not fading away. Is someone out there has a solution to this ?

Update

I solved the hiding issue, using @hahaha solution. I just need a view to be the background of the status bar, here is my code.

AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];

self.StatusBarOrange = [[UIView alloc] initWithFrame:CGRectMake(0, 0, appDelegate.window.frame.size.width, 20)];    
[self.StatusBarOrange setBackgroundColor:[UIColor orangeColor]];
[appDelegate.window.rootViewController.view addSubview:self.StatusBarOrange];

and now everything works perfectly!

like image 405
xeravim Avatar asked Oct 04 '13 15:10

xeravim


People also ask

How do I hide my status bar on Iphone 7?

To completely hide it on the home screen, open up an app, such as Settings, and wait about three to four seconds. Press the home button again, and the status bar will be completely gone. The status bar will only be hidden on your home screen, so you'll still see it while using apps.


1 Answers

You need to call

[UIViewController setNeedsStatusBarAppearanceUpdate];

from within an animation block as in the following example:

@implementation SomeViewController {
    BOOL _statusBarHidden;
}

- (BOOL)prefersStatusBarHidden {
    return _statusBarHidden;
}

- (void)showStatusBar:(BOOL)show {
 [UIView animateWithDuration:0.3 animations:^{
        _statusBarHidden = !show;
        [self setNeedsStatusBarAppearanceUpdate];
    }];
}

@end
like image 166
Werner Altewischer Avatar answered Sep 28 '22 12:09

Werner Altewischer