How to hide/show tab bar of a view with a navigation bar in iOS?(如何在 iOS 中使用导航栏隐藏/显示视图的标签栏?)
问题描述
我有一个带有导航栏和标签栏的视图.我想要发生的是在某个视图上隐藏标签栏,并在用户更改视图时再次显示标签栏.
I have views with a navigation bar and a tab bar. What I would like to happen is to hide the tab bar on a certain view and show the tab bar again when the user changes views.
我看到了一段隐藏标签栏的代码:
I saw a snippet of code for hiding the tab bar:
-(void)makeTabBarHidden:(BOOL)hide
{
// Custom code to hide TabBar
if ( [tabBarController.view.subviews count] < 2 ) {
return;
}
UIView *contentView;
if ( [[tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] ) {
contentView = [tabBarController.view.subviews objectAtIndex:1];
} else {
contentView = [tabBarController.view.subviews objectAtIndex:0];
}
if (hide) {
contentView.frame = tabBarController.view.bounds;
}
else {
contentView.frame = CGRectMake(tabBarController.view.bounds.origin.x,
tabBarController.view.bounds.origin.y,
tabBarController.view.bounds.size.width,
tabBarController.view.bounds.size.height - tabBarController.tabBar.frame.size.height);
}
tabBarController.tabBar.hidden = hide;
}
来自:http://nickwaynik.com/iphone/hide-tabbar-in-an-ios-app/
我在希望隐藏标签栏的视图上调用它
I call this on the view wherein I want the tab bar hidden
[self makeTabBarHidden:YES];
当我在该视图上显示/隐藏它时它工作正常,但是当我导航回上一个视图时,那里的标签栏也被隐藏了.我尝试在视图的 viewDidUnload、viewWillDisappear、viewDidDisappear 函数中调用该函数,但没有任何反应.在前一个视图的viewDidLoad、viewWillAppear、viewDidAppear函数中调用该函数时也是如此.
it works fine when i show/hide it on that view but when I navigate back to the previous view, the tab bar there is also hidden. I tried calling that function in the view's viewDidUnload, viewWillDisappear, viewDidDisappear functions but nothing happens. The same is true when the function is called in the previous view's viewDidLoad, viewWillAppear, viewDidAppear functions.
推荐答案
你可以设置 UIViewController.hidesBottomBarWhenPushed 来代替:
You can set the UIViewController.hidesBottomBarWhenPushed instead:
DetailViewController *detailViewController = [[DetailViewController alloc] init];
detailViewController.hidesBottomBarWhenPushed = YES;
[[self navigationController] pushViewController:detailViewController animated:YES];
[detailViewController release];
这篇关于如何在 iOS 中使用导航栏隐藏/显示视图的标签栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 iOS 中使用导航栏隐藏/显示视图的标签栏?
基础教程推荐
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
