6

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Peter Tao
  • 1,668
  • 6
  • 18
  • 29

2 Answers2

14

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 ;]

Oleh Zayats
  • 2,423
  • 1
  • 16
  • 26
  • Are you sure that this is gonna make it through the app store review? Do you have proof? – Lukas Würzburger Nov 17 '17 at 10:28
  • 2
    Hi @lufritz! If you're concerned about the private key you can just try to make 2 substrings and join them. Did it once and passed review after was rejected previously with a single string. Nobody will review your code manually and the analyzer will not check all possible combinations. The project is under NDA so cannot show you. P.S. I've used private classes/keys only a few times when there's no other way around and the client wanted something done asap. It is unsafe to do such stuff in production. – Oleh Zayats Nov 17 '17 at 11:51
  • This is great! Had no idea you can do this. I see no reason why this would not make it past app review. – msweet168 Oct 31 '18 at 17:35
0

They are most likely either grabbing the window the status bar is in and animating that or they are placing a window above the status bar with a view and animating that. I don't have the app to check but it has to be either of these two methods. To place a window above the status bar I think it is window.windowLevel = UIWindowLevelStatusBar + 1 so that it will be above your status bar. If they are grabbing the reference you have to loop through the application windows to find it and I have never tried to find the Statusbar window but I have grabbed the keyboard window. If the clock is indeed being pulled down then it could be a combination of both the getting the window the status bar is in and adding a window above and animating both. Facebook grabs the keyboard window to scroll it up in Facebook Messenger. Hope this helps you.

Edit: I found an example of getting the status bar window here.

Also I would recommend using CAAnimations and avoid really changing anything. Just use the animations to give that appearance.

Community
  • 1
  • 1
agibson007
  • 4,173
  • 2
  • 19
  • 24