Skip to content

Instantly share code, notes, and snippets.

@borut-t
Created September 10, 2013 10:08
Show Gist options
  • Save borut-t/6507423 to your computer and use it in GitHub Desktop.
Save borut-t/6507423 to your computer and use it in GitHub Desktop.

Revisions

  1. borut-t created this gist Sep 10, 2013.
    51 changes: 51 additions & 0 deletions UITabBarController+extra.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    //
    // UITabBarController+extra.m
    //
    // Created by Borut Tomažin on 10/1/12.
    // Copyright (c) 2012 Borut Tomažin. All rights reserved.
    //

    #import "UITabBarController+extra.h"

    #define kAnimationDuration .3

    @implementation UITabBarController (extra)

    - (void)setHidden:(BOOL)hidden animated:(BOOL)animated
    {
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    float fHeight = screenRect.size.height;
    if (UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
    fHeight = screenRect.size.width;
    }

    if (!hidden) {
    fHeight -= self.tabBar.frame.size.height;
    }

    CGFloat animationDuration = animated ? kAnimationDuration : 0.f;
    [UIView animateWithDuration:animationDuration animations:^{
    for (UIView *view in self.view.subviews){
    if ([view isKindOfClass:[UITabBar class]]) {
    [view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)];
    }
    else {
    if (hidden) {
    [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];
    }
    }
    }
    } completion:^(BOOL finished){
    if (!hidden){
    [UIView animateWithDuration:animationDuration animations:^{
    for(UIView *view in self.view.subviews) {
    if (![view isKindOfClass:[UITabBar class]]) {
    [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];
    }
    }
    }];
    }
    }];
    }

    @end