将UIViewController推送在UITabBar上方

4
我有一个名为ListVC的UIViewController。ListVC有一个UITabBar,用户可以使用它来切换标签。它还有UINavigationController。
在ListVC中,我有一个按钮,当按下时,我希望使用NavigationController将一个名为DetailVC的新ViewController推送到该页面。我想要以不带UITabBar的方式呈现DeatilVC。
问题是,在使用pushViewController(animated)方法时,视图仍具有UITabBar。
如何将视图推送到UITabBar上方(我不想模态呈现它)?
在Whatsapp中选择聊天列表中的聊天时,您可以看到它的示例。图片:

Imafe

代码: self.navigationController?.pushViewController(detailVC, animated: true) 谢谢!

self.navigationController?.pushViewController(detailVC, animated: true) 不能解决你的问题。这不是真的。也许你做了其他的事情? - pacification
将 tabBarcontroller 嵌入到 navigationController 中。 - SPatel
@SPatel 你是什么意思?能否请你再解释一下(我没有使用Storyboard)。 - FS.O6
将tabBarController设置为NavigationController的根视图控制器。 - SPatel
尝试使用self.tabBarController.navigationController?.pushViewController(detailVC, animated: true) - SPatel
显示剩余6条评论
6个回答

9
在您按下时编写以下代码:
yourViewController.hidesBottomBarWhenPushed = true

您也可以在故事板上从推送隐藏选项卡栏。选择您将要推送的视图控制器并勾选“推送时隐藏底部工具栏”:

enter image description here


它不会在选项卡栏上方显示视图,只是将其隐藏(且没有任何动画效果)。 - FS.O6
你是在展示视图控制器还是推出视图控制器? - iVarun
推送。例如,在Whatsapp中,您可以看到我尝试实现的内容。 - FS.O6
我已经添加了一个图像,展示我想要实现的内容。请看一下。 - FS.O6
当你推送时,你是否添加了以下代码 yourViewController.hidesBottomBarWhenPushed = true - iVarun
我已经尝试过了。它只是隐藏了选项卡栏(即使没有动画)。我想要推送的视图在其父视图的选项卡栏上方。 - FS.O6

2

1. 当您按下时,请编写以下代码:

let yourVC = Storyboard.Main.storyboard().instantiateViewController(withIdentifier: "YourViewController") as! YourViewController
yourVC.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(yourVC, animated: true)

enter image description here


1

好的,我已经解决了这个问题。在推送代码之前和之后,我必须两次添加hidesBottomBarWhenPushed

self.hidesBottomBarWhenPushed  = true
self.navigationController?.pushViewController(detailVC, animated: true)
self.hidesBottomBarWhenPushed = false

根据文档,hidesBottomBarWhenPushed 应该在推送视图控制器上调用,而不是从推送的视图控制器上调用。https://developer.apple.com/documentation/uikit/uiviewcontroller/1621863-hidesbottombarwhenpushed?language=objc - pacification

0

试一下这个

override func viewWillDisappear(_ animated: Bool) {
    self.tabBarController?.tabBar.isHidden = true
}

override func viewWillAppear(_ animated: Bool) {
    self.tabBarController?.tabBar.isHidden = false
}

我已经添加了一张图片。这正是我想要实现的效果。不隐藏选项卡栏,将一个VC推到其上方。 - FS.O6
你是在推送到导航控制器还是视图控制器?如果你正在使用导航控制器推送一个视图控制器,请尝试移除该导航控制器并直接推送到视图控制器。 - Shezad
你是什么意思?我是这样推送它的:self.navigationController?.pushViewController(detailVC, animated: true) - FS.O6
你在ListVC中有你的tabbar,对吧? - Shezad
使用这段代码,它会在底部变黑。 - Priyank Patel
显示剩余8条评论

0

前往故事板并检查在推送时隐藏底部栏

enter image description here

或者在 DetailVC 中直接输入 viewDidLoad 方法 hidesBottomBarWhenPushed = true


它不会在选项卡栏上方显示视图,只是将其隐藏(而且没有任何动画效果)。 - FS.O6
我已经添加了一个图像,展示我想要实现的内容。请看一下。 - FS.O6
@FS.O6,还是不明白问题所在。也许你有视频或gif示例吗? - pacification
我不想隐藏选项卡栏。我想要将一个VC推到它的顶部。 - FS.O6

0
iOS的UINavigationViewController和UITabBar 你有三个选项:
1. 在故事板中:选择ViewController -> 属性检查器 -> 在推送时隐藏底部栏 2. 在代码中:vc.hidesBottomBarWhenPushed 3. 在ViewController的代码中:
public override var hidesBottomBarWhenPushed: Bool {
    get { return true }
    set { }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接