【发布时间】:2011-11-26 10:43:21
【问题描述】:
视觉上这就是我想要的
我有一个UITabBarController。当用户进入中间选项卡时,我想隐藏UITabBar。中间选项卡加载 B 类的视图控制器。这是流行的相机应用程序Instagram 的行为。他们的中间选项卡加载了一个全屏相机。
------------- ------------- -------------
| VC | | VC | | VC |
| for | | for | | for |
| A | | B | | C |
| | | | | |
|------------ | | |------------
{ A } B | C | | | | A | B { C }
------------- ------------- -------------
所有其他相关 StackExchange 问题的建议解决方案
我们已经有几十个关于如何在推送特定视图控制器时隐藏 UITabBar 的问题。普遍的共识是这样的:
b.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:b
animated:YES];
我的问题是,我从未对 UITabBarController 进行子类化。我在 Interface Builder 中创建了它。我从不手动推送我的视图控制器,所以上述解决方案对我不起作用。
尝试失败 1
在我的中间视图控制器中,我在构造函数中打开了hidesBottomBarWhenPushed。这没有效果。
@implementation B
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.hidesBottomBarWhenPushed = YES;
}
return self;
}
尝试失败 2
我还尝试将我的应用委托分配为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;
}
}
【问题讨论】:
-
但是你可以继承它并让 IB 返回你的类的一个实例。
标签: iphone objective-c ios cocoa-touch