隐藏在滚动/滑动后,UINavigationBar不再显示

时间:2016-11-07 03:59:03

标签: ios swift xcode uinavigationbar statusbar

正如标题所说,导航栏在将其隐藏在滚动后不会显示出来。我尝试在xCode中以及以编程方式设置它。无论哪种方式,问题仍然存在。 enter image description here

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

        navigationController?.hidesBarsOnSwipe = true
    }

这是隐藏navBar后的样子。请注意,状态栏颜色也从白色变为黑色。

enter image description here

在viewDidLoad中我有:

 //MARK: navigation bar styles
        self.navigationController?.navigationBar.backgroundColor = UIColor.init(red: 26/255, green: 24/255, blue: 24/255, alpha: 1)
        self.navigationController?.navigationBar.clipsToBounds = true
        self.navigationController?.navigationBar.titleTextAttributes =  [NSFontAttributeName:UIFont(name:"GillSans", size: 20)!]

有没有人有这个好的解决方案?提前感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

试试这段代码:

注意:当您将导航栏背景设置为接近黑色时。您必须将状态栏内容更改为浅色。

//使用以下代码更新您的plist

 View controller-based status bar appearance = NO

在ViewController中:

    title = "Some Title"

    navigationController?.navigationBar.barTintColor = UIColor(red: 26/255, green: 24/255, blue: 24/255, alpha: 1)
    navigationController?.navigationBar.tintColor = UIColor.white

    //Title Colour and Font
    navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.white, NSFontAttributeName:UIFont(name:"Arial", size: 20)!]

    navigationController?.navigationBar.clipsToBounds = false
    UIApplication.shared.statusBarStyle = .lightContent
   }


   override func viewDidAppear(_ animated: Bool) {

    navigationController?.hidesBarsOnSwipe = true

    }

输出:

enter image description here