如何在我没有子类的UITabBarController上隐藏UITabBar?

问题描述 投票:4回答:1

Visually this is what I want

我有一个UITabBarController。我想在用户进入中间选项卡时隐藏UITabBar。中间选项卡加载了B类的视图控制器。这是流行的相机应用程序Instagram的行为。他们的中间标签加载全屏相机。

-------------    -------------    -------------
|     VC    |    |     VC    |    |     VC    |
|    for    |    |    for    |    |    for    |
|     A     |    |     B     |    |     C     |
|           |    |           |    |           |
|------------    |           |    |------------
{ A } B | C |    |           |    | A | B { C }
-------------    -------------    -------------

Proposed solution from all other related StackExchange questions

我们已经有很多关于如何在推送特定视图控制器时隐藏UITabBar的问题。普遍的共识是这样的:

b.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:b
                                     animated:YES];

我的问题是,我从未将UITabBarController子类化。我在Interface Builder中创建了它。我从不手动推动我的视图控制器,因此上述解决方案对我不起作用。

Failure attempt 1

在我的中间视图控制器中,我打开构造函数的hidesBottomBarWhenPushedin。这没有效果。

@implementation B

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.hidesBottomBarWhenPushed = YES;
    }
    return self;
}

Failure attempt 2

我还尝试将我的app委托指定为UITabBarControllerDelegate。当UITabBarController通知我已经点击了一个标签时,我只为中间视图控制器打开hidesBottomBarWhenPushed。这也未能掩盖UITabBar

#pragma mark UIApplicationDelegate

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
    [window addSubview:self.rootViewController.view];
    [window makeKeyAndVisible];
    self.rootViewController.delegate = self;
}

#pragma mark UITabBarControllerDelegate

- (void) tabBarController:(UITabBarController *)tabBarController 
didSelectViewController:(UIViewController *)viewController
{
    if ([viewController isKindOfClass:[B class]]) {
        viewController.hidesBottomBarWhenPushed = YES;
    } else {
        viewController.hidesBottomBarWhenPushed = NO;
    }
}
iphone objective-c ios cocoa-touch
1个回答
0
投票
- (void) hidetabbar:(BOOL)hiddenTabBar
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    for(UIView *view in self.uiTabBarController.view.subviews){
        if([view isKindOfClass:[UITabBar class]]) {

            if (hiddenTabBar) {
                [view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
            } else {
                [view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
            }
        } else {
            if (hiddenTabBar) {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
            } else {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
            }
        }
    }
    [UIView commitAnimations];  
    hiddenTabBar = !hiddenTabBar;
}
© www.soinside.com 2019 - 2024. All rights reserved.