Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Hide and Show TabBarController in iPhone

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 579
    Comment on it

    Sometimes we need to hide or show TabBarController from the bottom of the screen then we can just use following functions to do so...

    In AppDelegate or Singleton class for .h class :-

    - (void) showTabBar:(UITabBarController *) tabbarcontroller;
    - (void) hideTabBar:(UITabBarController *) tabbarcontroller;
    

    for .m class

    /*===================================================================================
    
    
    

    // Tabbar controller at bottom. // Hide and show logic functions for different screens. ===================================================================================*/

    • (void) showTabBar:(UITabBarController *) tabbarcontroller { CGRect screenRect = [[UIScreen mainScreen] bounds]; float fHeight = screenRect.size.height - tabbarcontroller.tabBar.frame.size.height;

      if( UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) ) { fHeight = screenRect.size.width - tabbarcontroller.tabBar.frame.size.height; }

      [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5];

      for(UIView *view in tabbarcontroller.view.subviews) { if([view isKindOfClass:[UITabBar class]]) { [view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)]; } else { [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)]; } } [UIView commitAnimations]; } //=======================================================================================

    • (void) hideTabBar:(UITabBarController *) tabbarcontroller { CGRect screenRect = [[UIScreen mainScreen] bounds]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; float fHeight = screenRect.size.height; if( UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) ) { fHeight = screenRect.size.width; }

      for(UIView *view in tabbarcontroller.view.subviews) { if([view isKindOfClass:[UITabBar class]]) { [view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)]; } else { [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)]; view.backgroundColor = [UIColor blackColor]; } } [UIView commitAnimations]; }

    where you want to call hide or show just write this:-

    // create object of AppDelegate or Singleton class like here...

    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    

    [appDelegate hideTabBar:self.tabBarController];

    or

    [appDelegate showTabBar:self.tabBarController];

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: