swift 将UIViewController推到UITabBar上方

lsmepo6l  于 2023-09-30  发布在  Swift
关注(0)|答案(6)|浏览(87)

我有一个UIViewController叫做ListVCListVC有一个UITabBar,用户可以用它切换标签。它也有UINavigationController
ListVC中,我有一个按钮,当按下它时,我想按下一个名为DetailVC的新ViewController(使用NavigationController)。我想展示没有UITabBarDeatilVC
问题是,当我使用pushViewController(animated)方法时,视图仍然有UITabBar
如何将视图推到UITabBar之上(我不想以模态方式呈现它)?
您可以在Whatsapp上从聊天列表中选择聊天时看到它的示例。图片:

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

ttygqcqt

ttygqcqt1#

当你推送的时候写下面的代码:

yourViewController.hidesBottomBarWhenPushed = true

你也可以隐藏标签栏上推从情节提要也。选择你要推的视图控制器,然后选中在推时隐藏底部栏:

gt0wga4j

gt0wga4j2#

1.当你推送的时候写下面的代码:

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

r1zhe5dt

r1zhe5dt3#

好了,我已经解决了这个问题。我不得不在push代码之前和之后添加hidesBottomBarWhenPushed两次:

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

4dbbbstv4#

转到故事板并检查Hide Bottom Bar On Push

或者直接输入DeatilVC viewDidLoad方法hidesBottomBarWhenPushed = true

yqkkidmi

yqkkidmi5#

试试这个

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

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

omvjsjqw6#

iOS UINavigationViewController和UITabBar

你有三个选择:
1.在情节提要中:选择ViewController -> Attributes Inspector -> Hide Bottom Bar On Push
1.代码:vc.hidesBottomBarWhenPushed
1.在ViewController代码中:

public override var hidesBottomBarWhenPushed: Bool {
    get { return true }
    set { }
}

相关问题