隐藏导航栏但显示带背景的状态栏

时间:2016-05-26 17:52:54

标签: ios swift uinavigationbar statusbar

我的导航栏设置为隐藏在滚动状态,但它也会随身携带状态栏的背景颜色,当我滚动时,会将白色状态栏文本留在我的内容之上。我希望它看起来类似于许多应用程序的方式,如果我的导航栏和状态栏具有带有白色文本的橙色背景,当滚动发生并且导航栏隐藏时,状态栏保留橙色背景。

UPDATE1:

尝试在视图中添加20的子视图,但它没有显示。我可能会遗漏一些东西,因为这是我第一次创建没有IB的应用程序。

我将此代码放入我的TableViewController中。我试过tableview。,查看。和super.view。他们似乎都没有工作。

let statusBarBG = UIView()
        statusBarBG.backgroundColor = UIColor.rgb(248, green: 148, blue: 6)
        super.view?.addSubview(statusBarBG)
        super.view?.addContstraintsWithFormat("V:|[v0(20)]", views: statusBarBG)
        super.view?.addContstraintsWithFormat("H:|[v0]|", views: statusBarBG)

更新2:

所以在尝试了几件事之后,我的视图会出现,但是它会在导航栏下面滚动并滚动显示,当用户滚动时会导致它消失。

FeedTVController:的UITableViewController

 let statusBarBG = UIView(frame: CGRect(x: 0.0, y: -44, width: UIScreen.mainScreen().bounds.width, height: 20))
            statusBarBG.backgroundColor = .redColor()  //UIColor.rgb(248, green: 148, blue: 6)
            self.view?.addSubview(statusBarBG)

App Delegate:

let feedController = FeedTVController()
        let navigationController = UINavigationController(rootViewController: feedController)
        let tabBarController = TabBarController()
        tabBarController.setViewControllers([vc1, vc2, vc3], animated: true)
        window?.rootViewController = tabBarController

3 个答案:

答案 0 :(得分:0)

将SuperView(ViewController视图)的背景颜色更改为橙​​色(或者您想要的状态栏默认颜色。

答案 1 :(得分:0)

没有代码,所以有两种方法可以隐藏你的导航栏:

如果您手动隐藏子类,那么它相对于用户向上滚动的数量(如Facebook)隐藏:然后不是一直隐藏导航栏,而是从屏幕左下方的20个点隐藏它

如果您使用内置的动画隐藏隐藏了navBar:然后添加一个连接到容器顶部的子视图,并且具有相同背景颜色的20点高,所以当导航栏消失时,子视图位于顶部。

答案 2 :(得分:0)

环顾四周后,我无法找到适合这种情况的解决方案。以合乎逻辑的方式思考我提出了一个解决方案,我希望能帮助人们解决同样的问题。

默认情况下,没有状态栏背景视图,因此我们需要创建一个并将其放在状态栏下但位于导航栏上方:

On viewDidLoad()

    self.navigationController?.hidesBarsOnSwipe = true

    /* creates a View using the navigation bar frame to place under the status bar but above the navigation bar */

    let statusBarView = UIView()
    statusBarView.backgroundColor = .blue
    statusBarView.frame = UIApplication.shared.statusBarFrame
    UIApplication.shared.keyWindow?.addSubview(statusBarView)
相关问题