ios 如何隐藏 UITabBar?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/815690/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to hide UITabBar?
提问by Ilya Suzdalnitski
In my app I have a tab bar. And in some views I as well have a toolbar. So when I come to those views with a toolbar it looks ugly - two bars at the bottom of the view. I thought that it would be a best solution to hide a tab bar when entering those particular views. But I just couldn't figure out how to do it in a right way. I tried to set UITabBarController's tabBar hidden property to YES, but it didn't work. And I as well tried to do the following thing in whatever view I am:
在我的应用程序中,我有一个标签栏。在某些视图中,我也有一个工具栏。因此,当我使用工具栏访问这些视图时,它看起来很丑 - 视图底部有两个条。我认为在输入这些特定视图时隐藏标签栏是最好的解决方案。但我只是不知道如何以正确的方式做到这一点。我试图将 UITabBarController 的 tabBar 隐藏属性设置为 YES,但它不起作用。无论我是什么观点,我也试图做以下事情:
self.hidesBottomBarWhenPushed = YES;
But it didn't work as well.
但它也没有奏效。
What is the right solution to this situation? I don't want to have 2 bars at any view.
这种情况的正确解决方案是什么?我不想在任何角度都有 2 个酒吧。
回答by Panagiotis Korros
You have to use set the hidesBottomBarWhenPushed property to YES on the controller that you are pushing and NOT to the UITabBarController.
您必须在要推送的控制器上将 hidesBottomBarWhenPushed 属性设置为 YES,而不是将其设置为 UITabBarController。
otherController.hidesBottomBarWhenPushed = YES;
[navigationController pushViewController: otherController animated: TRUE];
Or you can set the property when you first initialize the controller you want to push.
或者您可以在首次初始化要推送的控制器时设置该属性。
回答by Vladimir Shutyuk
Interface builder has checkbox for view controller embedded in tab bar - Hides bottom bar on push. In easy cases no need to do it through code now.
界面构建器具有嵌入在选项卡栏中的视图控制器复选框 - 在推送时隐藏底部栏。在简单的情况下,现在不需要通过代码来完成。
For @Micah
对于@Micah
回答by SAKrisT
Don't use this solution!
不要使用此解决方案!
BOOL hiddenTabBar;
UITabBarController *tabBarController;
- (void) hideTabBar {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.4];
for(UIView *view in tabBarController.view.subviews)
{
CGRect _rect = view.frame;
if([view isKindOfClass:[UITabBar class]])
{
if (hiddenTabBar) {
_rect.origin.y = [[UIScreen mainScreen] bounds].size.height-49;
[view setFrame:_rect];
} else {
_rect.origin.y = [[UIScreen mainScreen] bounds].size.height;
[view setFrame:_rect];
}
} else {
if (hiddenTabBar) {
_rect.size.height = [[UIScreen mainScreen] bounds].size.height-49;
[view setFrame:_rect];
} else {
_rect.size.height = [[UIScreen mainScreen] bounds].size.height;
[view setFrame:_rect];
}
}
}
[UIView commitAnimations];
hiddenTabBar = !hiddenTabBar;
}
回答by titusmagnus
I too struggled with this for a while. Hiding the tab bar is one step in the right direction, but leaves a black rectangle behind. The trick is to resize the layer that backs the UIViewController's view.
我也为此挣扎了一段时间。隐藏标签栏是朝着正确方向迈出的一步,但会留下一个黑色矩形。诀窍是调整支持 UIViewController 视图的层的大小。
I have written a small demo here with a solution:
我在这里写了一个带有解决方案的小演示:
https://github.com/tciuro/FullScreenWithTabBar
https://github.com/tciuro/FullScreenWithTabBar
I hope this helps!
我希望这有帮助!