如何在Swift中立即隐藏导航栏?

问题描述 投票:3回答:7

我的UIViewController嵌入在导航控制器中:

enter image description here

我试过setNavigationBarHidden:animated:来隐藏通知栏。它有效,但延迟约2秒。这是截图:

enter image description here

我的用法是在viewDidLoad()中添加它:

override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationController?.setNavigationBarHidden(true, animated: false)
}

如何在屏幕启动时立即隐藏navigationbar

ios swift uinavigationcontroller uinavigationbar
7个回答
13
投票

当UIViewController初始化qazxsw poi时隐藏导航栏


3
投票

ViewController.navigationController?.setNavigationBarHidden(true, animated: false)

每个应用程序必须提供启动文件或至少一个静态图像。

延迟是由主故事板文件中的启动屏幕引起的。不要将启动屏幕文件设置为According the official document文件。

Main.storyboard

Project settings > General -> App Icons and Launch Images -> Launch Screen File

将其设置为另一个故事板:

enter image description here


2
投票

Add this line indside view did load method

enter image description here

否则直接从StoryBoard执行此操作

//设置顶部栏无

override func viewDidLoad() { super.viewDidLoad() self.navigationController?.navigationBarHidden = true } 我希望这会对你有所帮助。


2
投票

试试这个...

enter image description here

2
投票

更好的方法是在viewWillLayoutSubviews()中实现您的代码。如果您使用导航或tapbar,这是一种更好的方法

斯威夫特4:

override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)

    self.navigationController?.navigationBarHidden = true
}

1
投票

您需要在viewDidLoad()方法中隐藏UINavigationBar

override func viewWillLayoutSubviews() {
    self.navigationController?.isNavigationBarHidden = true
}

1
投票

对于迅捷3: -

override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBarHidden = true 
}
© www.soinside.com 2019 - 2024. All rights reserved.