How the official iOS app for Twitter changes the status bar with custom text

The new official Twitter app for iOS changes the status bar, as in the picture above. How to implement such a function?

[ image source ]

+7
source share
1 answer

Here's how I do it in my rotating animation application:

-(void)showStatusBarMessage:(NSString *)message hideAfter:(NSTimeInterval)delay { __block UIWindow *statusWindow = [[UIWindow alloc] initWithFrame:[UIApplication sharedApplication].statusBarFrame]; statusWindow.windowLevel = UIWindowLevelStatusBar + 1; UILabel *label = [[UILabel alloc] initWithFrame:statusWindow.bounds]; label.textAlignment = UITextAlignmentCenter; label.backgroundColor = [UIColor blackColor]; label.textColor = [UIColor grayColor]; label.font = [UIFont boldSystemFontOfSize:13]; label.text = message; [statusWindow addSubview:label]; [statusWindow makeKeyAndVisible]; label.layer.transform = CATransform3DMakeRotation(M_PI * 0.5, 1, 0, 0); [UIView animateWithDuration:0.7 animations:^{ label.layer.transform = CATransform3DIdentity; }completion:^(BOOL finished){ double delayInSeconds = delay; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [UIView animateWithDuration:0.5 animations:^{ label.layer.transform = CATransform3DMakeRotation(M_PI * 0.5, -1, 0, 0); }completion:^(BOOL finished){ statusWindow = nil; [[[UIApplication sharedApplication].delegate window] makeKeyAndVisible]; }]; }); }]; } 

I use it in a category on a UIViewController to use it from any controller in the application.

EDIT: Requires QuartzCore.framework for reference and #import <QuartzCore/QuartzCore.h> for adding.

+14
source

All Articles