Twitter如何官方iOS应用更改与自定义文本
这里是我如何做到这一点在我的应用程序有一个旋转的动画:
-(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>
被添加。
我真的想知道这背后的逻辑是什么,你能解释一下吗?他们隐藏状态栏并显示他们的,或者是什么? –
除非他们告诉他们怎么做,否则你只能假设他们是怎么做的。我只在顶部隐藏UIWindow实例,添加一个标签,制作动画,然后删除窗口 – Moxy
谢谢,我会试一试。 –
作为iOS应用程序的消费者,当应用程序执行此操作时,我不喜欢它。状态栏不是应用程序的一部分;它是系统的一部分。不要触摸它;这不是你的混乱。你已经有了整个屏幕的其余部分来创建一个创造性的用户界面。请独自离开那个区域。 –