我有一个应用程序,你点击UIImageView,按钮淡出并重新进入。状态栏的功能相同,只是它快速进入。有没有办法计算其淡入时间以匹配我的按钮时间?这是我的.m文件,其中包含按钮和状态栏的代码。
的.m
- (void)viewDidLoad
{
////Loads UIImageView from URL
todaysWallpaper.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.inkdryercreative.com/daily/archive/mondays/images/062-mondays-960x640-A.jpg"]]];
_buttonsVisible = false;
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTapped:)];
[todaysWallpaper addGestureRecognizer:tapGesture];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
- (void)imageTapped:(UIGestureRecognizer *)sender {
float targetA = 0;
if(_buttonsVisible == NO) {
targetA =1.0;
} else {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(imageTapped:) object:nil];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
}
[UIView beginAnimations:@"MoveAndStrech" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationBeginsFromCurrentState:YES];
homeButton.alpha = targetA;
infoButton.alpha = targetA;
saveButton.alpha = targetA;
tweetButton.alpha = targetA;
[UIView commitAnimations];
_buttonsVisible = !_buttonsVisible;
if(_buttonsVisible) {
[self performSelector:@selector(imageTapped:) withObject:nil afterDelay:100.0];
[[UIApplication sharedApplication] setStatusBarHidden:NO ];
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
}
}
任何帮助或指导都将受到极大的赞赏。我的客户想要在星期二之前完成这项工作,或者找其他人来做这件事。我把我的生命投入到这个应用中,所以如果你能帮助分享知识,请。感谢
答案 0 :(得分:8)
您可以将其包装在动画块中。只需使用setStatusBarHidden:
方法而不是setStatusBarHidden:withAnimation:
[UIView beginAnimations:@"foo" context:nil];
[UIView setAnimationDuration:1.0];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[UIView commitAnimations];
答案 1 :(得分:3)
您可以尝试这是所有iOS设备的单行代码:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
希望有所帮助......
答案 2 :(得分:3)
尝试使用以下代码设置状态栏:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
答案 3 :(得分:1)
你可以做的是创建你自己的NavigationBar(不要使用UINavigationController的UINavigationBar) - 然后你可以自定义它并轻松地为它分配动画属性,如alpha。