【问题标题】:Swift hide the navigation barSwift隐藏导航栏
【发布时间】:2021-03-28 11:25:37
【问题描述】:

我正在处理一个项目,并希望在我的应用程序中隐藏导航栏。我已经在网上找到了一些隐藏栏的代码,但是当我隐藏它时,向后滑动功能会禁用。所以我不想有导航栏,但我想有滑动返回功能。

我已经尝试过这段代码:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    navigationController?.setNavigationBarHidden(true, animated: animated)
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    navigationController?.setNavigationBarHidden(false, animated: animated)
}

这里也有这段代码:

self.navigationController?.navigationBar.isHidden = true

等等……

【问题讨论】:

  • 你设置 self.navigationController?.interactivePopGestureRecognizer?.delegate = self self.navigationController?.interactivePopGestureRecognizer?.isEnabled = true For UIViewController??
  • 是的,我试过了,但还是不行。
  • 非常感谢。它现在正在工作

标签: ios swift uinavigationcontroller uinavigationbar


【解决方案1】:

当您隐藏导航栏时,滑动返回将不起作用。也许你想要我建议你的完全透明的导航栏,因为你可以用这样的安全区域限制视图,你可以滑动返回。

    let navBarAppearance = UINavigationBarAppearance()
    navBarAppearance.configureWithTransparentBackground()
    navigationController?.navigationBar.standardAppearance = navBarAppearance
    navigationController?.navigationBar.scrollEdgeAppearance = navBarAppearance
    navigationController?.navigationBar.compactAppearance = navBarAppearance
    self.navigationController?.navigationBar.prefersLargeTitles = false
    self.navigationController?.navigationBar.topItem?.title? = "Back"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多