我正在通过一个表视图以编程方式构建视图,其中包含底部选项卡栏。当选择一个表格单元时,我希望这个底部栏消失。我可以使用以下方法实现:
self.tabBarController.tabBar.hidden = YES;
但视图的大小仍然像选项卡栏仍在那里一样。 我发现如果视图是在Storyboard上构建的,并通过设置复选框“在推送时隐藏底部栏”,则视图会调整大小以占用选项卡栏留下的空间。 我该如何以编程方式实现这一点?
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:self.anotherViewController animated:animated];
对于你要推送的特定视图控制器,使用以下代码:
TheViewController* theController = [[TheViewController alloc] initWithNibName:@"TheViewController" bundle:nil];
theController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:theController animated:YES];
[theController release];
现在TabBar将自动隐藏和显示。享受这段时间吧 :)
使用 Swift
:
let viewController = CustomViewController()
viewController.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(viewController, animated: true)