2

我有一个应用程序,您可以在其中点击 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];
}
}

任何帮助或指导将不胜感激。我的客户希望在星期二之前完成这项工作,或者找其他人来完成这项工作。我已经把我的生命投入到这个应用程序中,所以如果你能帮助分享知识,请。谢谢

4

4 回答 4

8

您可以将其包装在动画块中。只需使用该setStatusBarHidden:方法而不是 setStatusBarHidden:withAnimation:

[UIView beginAnimations:@"foo" context:nil];
[UIView setAnimationDuration:1.0];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[UIView commitAnimations];
于 2012-04-15T16:34:28.797 回答
3

尝试使用以下代码设置状态栏:

[[UIApplication sharedApplication] setStatusBarHidden:YES
                                        withAnimation:UIStatusBarAnimationFade];
于 2013-07-18T10:44:20.547 回答
3

你可以试试这个,它是所有 iOS 设备的单行代码:

[[UIApplication sharedApplication] setStatusBarHidden:YES
                                        withAnimation:UIStatusBarAnimationFade];

希望能帮助到你..

于 2012-11-29T12:41:10.130 回答
1

您可以做的是创建自己的 NavigationBar(不要使用 UINavigationController 的 UINavigationBar) - 然后您可以自定义它并轻松为其分配动画属性,例如 alpha。

于 2012-04-15T16:11:27.543 回答