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.
//
// 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment