2

I have an app where you tap a UIImageView and the buttons fade out and come back in. The Status bar does the same except it just comes in to quick. Is there a way to time its fade in to match my buttons timing ? Here is my .m file where the code for the buttons and status bar.

.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];
}
}

Any help or guidance would be appreciated greatly. My client wants to have this done by tuesday or find someone else to do this. I have put my life into this app so please if you can help share the knowledge. thanks

Gabriel
  • 328
  • 5
  • 16

4 Answers4

8

You could wrap it in the animation block. Just use the setStatusBarHidden: method instead of setStatusBarHidden:withAnimation:

[UIView beginAnimations:@"foo" context:nil];
[UIView setAnimationDuration:1.0];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[UIView commitAnimations];
Alex Cio
  • 6,014
  • 5
  • 44
  • 74
GreyHands
  • 1,734
  • 1
  • 18
  • 30
  • +1, didn't know you can put that in an animation block. Is there a list of things that can be animated? – noRema Feb 08 '13 at 13:51
3

You can try this it is the single line code for all iOS devices:

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

Hope it helps..

Alex Cio
  • 6,014
  • 5
  • 44
  • 74
Meet
  • 4,904
  • 3
  • 24
  • 39
3

Try setting the status bar using the below code:

[[UIApplication sharedApplication] setStatusBarHidden:YES 
                                        withAnimation:UIStatusBarAnimationFade];
Alex Cio
  • 6,014
  • 5
  • 44
  • 74
Satya
  • 93
  • 8
1

What you could do is create your own NavigationBar (don't use the UINavigationController's UINavigationBar) - You can then customize it and assign it easily animatable properties such as alpha.

Stavash
  • 14,244
  • 5
  • 52
  • 80