我有导航栏和标签栏的视图.我想要发生的是隐藏某个视图上的标签栏,并在用户更改视图时再次显示标签栏.
我看到一段用于隐藏标签栏的代码:
-(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;
}
Run Code Online (Sandbox Code Playgroud)
来自:http://nickwaynik.com/iphone/hide-tabbar-in-an-ios-app/
我在视图中调用它,我希望隐藏标签栏
[self makeTabBarHidden:YES];
Run Code Online (Sandbox Code Playgroud)
当我在该视图上显示/隐藏它时,它工作正常但当我导航回到上一个视图时,那里的标签栏也是隐藏的.我试着打电话给在视图中的该功能viewDidUnload,viewWillDisappear,viewDidDisappear功能,但没有任何反应.当函数被调用在前面视图的情况也是如此viewDidLoad, …
我有一个自定义UIToolbar的选项卡栏隐藏时显示的自定义。工具栏按钮太靠近iPhone X上的主页指示器:
let toolbar = UIToolbar()
let height = tabBarController?.tabBar.frame.height
toolbar.frame = CGRect(x: 0, y: view.bounds.height - height, width: view.bounds.width, height: height)
toolbar.autoresizingMask = [.flexibleWidth, .flexibleTopMargin]
view.addSubview(toolbar)
Run Code Online (Sandbox Code Playgroud)
这就是我想要的样子(邮件应用)^
由于这是一个自定义视图,因此我知道可以更改y位置并将其移动到安全区域的底部,但是我宁愿移动按钮。我使用的是普通UIBarButtonItem格式,中间使用灵活的空格。