状态栏可见性在iOS上不统一

时间:2017-11-16 04:05:26

标签: ios swift xcode9 swift3.2

我正在从8开始将iOS应用程序迁移到XCode9。我不确定导致什么,但看起来Swift 3.2 / Xcode 9的表现非常糟糕。

所以这个我正在开发的应用程序在所有视图控制器上都有状态栏,所以它已经存在,但是在迁移之后,它开始只显示主视图。通过选项卡按钮更改视图,它将变为空白,如下面的屏幕截图所示。

Home view

Another view

View controller-based status bar appearanceNOHide Status BarOFF

我添加了setNeedsStatusBarAppearanceUpdate()及其参数,但仍无效。

此处"另一个视图"

的ViewController代码
import UIKit

class InfoViewController: UITableViewController {

private var threads: [Info] = []
private var loading: Bool = false
private var hasNext: Bool = true

private var selectedThread: Info?
private var noInfoView: UIView?

internal var shouldRefresh: Bool = true
private var pagingIndicatorView: UIActivityIndicatorView!

private var timer: Timer?
private var poolingInterval: TimeInterval = 60 * 3

private var shouldClearThread: Bool = false
private var nextViewController: InfoDetailViewController?

let RequireCheckStatusForMessagesNotificationKey = "RequireCheckStatusForMessagesNotificationKey"

deinit {
    NotificationCenter.default.removeObserver(self)
    stopPooling()
}

override func viewDidLoad() {
    super.viewDidLoad()
    setNeedsStatusBarAppearanceUpdate()
    tableView.contentInset.bottom = 40

    pagingIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.gray)
    pagingIndicatorView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50)
    pagingIndicatorView.hidesWhenStopped = true

    NotificationCenter.default.addObserver(self, selector: #selector(InfoViewController.requireCheckInfosForMessagesNotificationHandler(notif:)), name: NSNotification.Name(rawValue: RequireCheckStatusForMessagesNotificationKey), object: nil)
}

var statusBarStyle : UIStatusBarStyle = .lightContent

override var preferredStatusBarStyle: UIStatusBarStyle {
    get {
        return statusBarStyle
    }
}

var statusBarStatus : Bool = false

override var prefersStatusBarHidden: Bool {
    get {
        return statusBarStatus
    }
}

1 个答案:

答案 0 :(得分:0)

View controller-based status bar appearance设置为YES并使用UIViewController的以下参数更容易:

override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
    get {
        return .slide
    }
}

var statusBarStyle : UIStatusBarStyle = .default

override var preferredStatusBarStyle: UIStatusBarStyle {
    get {
        return statusBarStyle
    }
}

var statusBarStatus : Bool = false

override var prefersStatusBarHidden: Bool {
    get {
        return statusBarStatus
    }
}

正如您在此处所见,我指的是我想要的值的自定义存储参数,因此更改状态栏的更新是更改这些自定义参数并调用statusBarNeedsUpdate。< / p>

尝试这种方法,如果它不能解决您的问题,请为您的控制器提供代码。