Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change status bar alpha

Tags:

ios

statusbar

In the Snapchat app, the status bar changes alpha when a table view is dragged down to reload.

This is the normal status bar This is the normal status bar

This is what happens when the table view is dragged down enter image description here

How is the status bar alpha changed? And how is the frame changed? Originally I thought it was a snapshot, but the clock changes as it normally should.

like image 226
Peter Tao Avatar asked Mar 16 '17 22:03

Peter Tao


1 Answers

This should do the trick for the fade animation:

/* Swift 3 */

let statusBarWindow = UIApplication.shared.value(forKey: "statusBarWindow") as? UIWindow
UIView.animate(withDuration: 2) {
    statusBarWindow?.alpha = 0.2
}

/* Objective-C */

UIWindow *statusBarWindow = (UIWindow *)[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"];
[UIView animateWithDuration:2.f 
                 animations:^{ [statusBarWindow setAlpha:0.2]; } 
                 completion:nil];

You can also set statusBarWindow's frame and move it how you want. Have fun ;]

like image 114
Oleh Zayats Avatar answered Sep 22 '22 01:09

Oleh Zayats