Monday, January 6, 2014

How to Show / Hide the tabbar controller in iOS






#pragma mark ==== Show / Hide the tabbar controller =====
//Show TabBar
+ (void) hideTabBar:(UITabBarController *) tabbarcontroller
{
    [self showHideTabBar:tabbarcontroller withDuration:0.25 xPosition:270];
}
//Hide TabBar
+ (void) showTabBar:(UITabBarController *) tabbarcontroller
{
   [self showHideTabBar:tabbarcontroller withDuration:0.2 xPosition:-270];
}

//Common method to Show / Hide TabBar
+ (void) showHideTabBar:(UITabBarController *) tabbarcontroller withDuration :(NSTimeInterval )duration xPosition :(float)xPos
{
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:duration];
    float fHeight = screenRect.size.height;
    ifUIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) )
    {
        fHeight = screenRect.size.width;
    }
    
    for(UIView *view in tabbarcontroller.view.subviews)
    {
        //NSLog(@"%@",view);
        if([view isKindOfClass:[UITabBar class]])
        {
            [view setFrame:CGRectMake(view.frame.origin.x+xPos, fHeight-49, 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 whiteColor];
        }
    }
    
    [UIView commitAnimations];
}


No comments:

Post a Comment