新的 iOS 官方 Twitter 应用程序更改状态栏,如上图所示。如何实现这样的功能?
[图片来源]
这是我在我的应用程序中使用旋转动画的方法:
-(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];
}];
});
}];
}
我将它放在 UIViewController 的一个类别中,以便从应用程序中的任何控制器中使用它。
编辑:需要QuartzCore.framework
引用和#import <QuartzCore/QuartzCore.h>
添加。