Hide the status bar and navigation bar at the same time, for example, in the Pictures application

I have a view with lots of text in it, so I want to allow the user to hide the statusBar + navigationBar with one click. I really like the hiding style in the Pictures app, where the statusBar and navigationBar are hiding (not sliding, just disappearing), with some Duration animation, so I tried to do something like this. Here is what I do in touchdidBegan methods:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent]; [UIView setAnimationDuration:0.5]; [UIView beginAnimations:@"" context:nil]; [[UIApplication sharedApplication] setStatusBarHidden:!([UIApplication sharedApplication].statusBarHidden) withAnimation:UIStatusBarAnimationNone]; [self.navigationController setNavigationBarHidden:(!self.navigationController.navigationBarHidden) animated:NO]; [UIView commitAnimations]; self.navigationController.navigationBar.translucent = !self.navigationController.navigationBar.translucent; // this is needed to make bars appear on top of my view. } 

But this does not hide the stripes at the same time. This makes them slide down. It has the same effect as this version of the method above:

 - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent]; // deleted UIView animation, changed animation type to "slide" [[UIApplication sharedApplication] setStatusBarHidden:!([UIApplication sharedApplication].statusBarHidden) withAnimation:UIStatusBarAnimationSlide]; // enabled animation for navBar [self.navigationController setNavigationBarHidden:(!self.navigationController.navigationBarHidden) animated:YES]; self.navigationController.navigationBar.translucent = !self.navigationController.navigationBar.translucent; // this is needed to make bars appear on top of my view. } 

If I get rid of the UIView animation and hide the bars without animation, they will hide and appear at the same time, but TOO fast. Maybe I'll go in the wrong direction. I would be grateful if someone would help me with this.

Edit: got a job

 - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // don't forget to set navigationBar.translucent to YES [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent]; [UINavigationBar setAnimationDuration:3.0]; [UINavigationBar beginAnimations:@"" context:nil]; [[UIApplication sharedApplication] setStatusBarHidden:!([UIApplication sharedApplication].statusBarHidden) withAnimation:NO]; if ([UIApplication sharedApplication].isStatusBarHidden) [self.navigationController.navigationBar setAlpha:0.0]; else [self.navigationController.navigationBar setAlpha:1.0]; [UINavigationBar commitAnimations]; } 
+6
source share
3 answers

check out this demo https://github.com/kirbyt/KTPhotoBrowser where you will find how to hide and show the status bar and navigation bar.

  • basically you need to use NSTimer to set auto-hide after 4 or 5 seconds. Storage Status Bar or Navigation Bar

  • You can also mark this timer by clicking the “Start” button to show or hide randomly.

Hope this helps you in your task. check out the Sample Demo above the Github link using the Barack point. You can easily find the hide function and show the Statusbar or NavigationBar.

+3
source

To hide the UIStatusBar with animation:

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

To hide a UINavigationBar with animation:

 [UINavigationBar beginAnimations:@"NavBarFade" context:nil]; self.navigationController.navigationBar.alpha = 1; [self.navigationController setNavigationBarHidden:YES animated:NO]; //Animated must be NO! [UINavigationBar setAnimationCurve:UIViewAnimationCurveEaseIn]; [UINavigationBar setAnimationDuration:1.5]; self.navigationController.navigationBar.alpha = 0; [UINavigationBar commitAnimations]; 
+4
source
 - (void)toggleStatusBarAndNavBar:(BOOL)hidden { UINavigationBar *navBar = self.navigationController.navigationBar; [[UIApplication sharedApplication] setStatusBarHidden:hidden withAnimation:UIStatusBarAnimationSlide]; [UIView animateWithDuration:0.35 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ // 先显示navigationBar if (!hidden) { [self.navigationController setNavigationBarHidden:hidden animated:NO]; } navBar.frame = CGRectMake(navBar.frame.origin.x, hidden ? -navBar.frame.size.height : 20, navBar.frame.size.width, navBar.frame.size.height); } completion:^(BOOL finished) { if (hidden) { [self.navigationController setNavigationBarHidden:hidden animated:NO]; } }]; } 

It will hide the status bar and navigation bar at the same time. Select UIStatusBarAnimationSlide for the status animation style. And change the navBar frame.

  • when hashed and hidden , equal NO . we must first change the navBar frame and then make the navBar hidden.
  • when shown, and hidden is equal to YES . first make a visual visualization of navBar, then change the frame.
  • we select UIViewAnimationOptionCurveEaseOut , it will look better.
0
source

All Articles