Search code examples
hidestatusbar

Hide/Unhide StatusBar, TabBar and NavigationBar on touch


How to hide/unhide the status bar, tab bar and navigation bar on touch using TapGesture. Can anyone give me the code for it?


Solution

  • Adding a tap gesture to the view

    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideUIComponents:)];
    [self.view addGestureRecognizer:tapGestureRecognizer];
    

    Then the function hideUIComponents

    - (void)hideUIComponents:(UITapGestureRecognizer*)tapGesture
    {
       [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
       [[self navigationController] setNavigationBarHidden:YES animated:YES];
    
       CATransition *animation = [CATransition animation];
       [animation setType:kCATransitionMoveIn];
       [[self.view.window layer] addAnimation:animation forKey:@"layerAnimation"];
       [self.tabBarController.tabBar setHidden:YES];
    }
    

    Unhide by reversing the values. I hope this helps.