iOS8:使用hidesBarsOnSwipe隐藏navigationBar后,如何使statusBar变得不透明? [英] iOS8: How do I make statusBar opaque after navigationBar is hidden using hidesBarsOnSwipe?

查看:126
本文介绍了iOS8:使用hidesBarsOnSwipe隐藏navigationBar后,如何使statusBar变得不透明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建iOS8应用程序。在我的tableview控制器上,我使用self.navigationController.hidesBarsOnSwipe = YES,在向上滑动手势上隐藏navigationBar。它运行良好,但我的statusBar变得透明,并在下面显示表格内容。

I am building iOS8 app. On my tableview controller, I am using self.navigationController.hidesBarsOnSwipe = YES, to hide the navigationBar on swipe up gesture. It is working nicely, but my statusBar becomes transparent and shows the table content underneath.

在情节提要上,状态栏是顶栏设置为推断

On storyboard, Status Bar are Top Bar are set to "Inferred"

我想:
1.保持我的状态栏不透明
2.保持与navigationBar
相同的颜色3.表格内容滚动在statusBar

I want to: 1. Keep my status bar opaque 2. Maintain the same color as the navigationBar 3. Table content scrolls underneath the statusBar

谢谢。

推荐答案

这是一个Swift解决方案:

Here is a Swift solution:

首先,将 UITableViewController 更改为 UIViewController 并添加一个 tableView 字段。
然后,按如下方式实施 viewDidLoad 方法:

First, change UITableViewController to UIViewController and add a tableView field. Then, implement your viewDidLoad method as follows:

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.delegate = self
    tableView.dataSource = self
    tableView.frame = view.frame
    view.addSubview(tableView)

    let topBar = UIView(frame: UIApplication.sharedApplication().statusBarFrame)
    topBar.backgroundColor = myDesiredColor
    view.addSubview(topBar)
}

这篇关于iOS8:使用hidesBarsOnSwipe隐藏navigationBar后,如何使statusBar变得不透明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆