The new official Twitter for iOS app changes statusbar just like in the picture above. How to implement such a feature?
[image source]
Here's how I do it in my app with a rotating animation:
-(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 have it in a category on UIViewController to use it from whatever controller in the app.
EDIT: Needs QuartzCore.framework
to be referenced and #import <QuartzCore/QuartzCore.h>
to be added.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With