如何在iOS 13中更改状态栏Alpha? [英] How can I change Status Bar Alpha in iOS 13?
问题描述
我想在iOS 13中更改状态栏Alpha。
I want to change the Status Bar Alpha in iOS 13.
let statusBarWindow = UIApplication.shared.value(forKey: "statusBarWindow") as? UIWindow
statusBarWindow?.alpha = 0.5
当我尝试此操作时,应用程序崩溃(线程1:信号SIGABRT)。
When I try this, the app crashes (Thread 1: signal SIGABRT).
推荐答案
由于未捕获的异常而终止应用程序
'NSInternalInconsistencyException ,原因:在UIApplication上名为-statusBar或
-statusBarWindow的应用程序:必须更改此代码,因为不再有状态栏或状态栏窗口。而是在窗口场景上使用
statusBarManager对象。’
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'App called -statusBar or -statusBarWindow on UIApplication: this code must be changed as there's no longer a status bar or status bar window. Use the statusBarManager object on the window scene instead.'
您可以参考以下答案来解决崩溃问题。
You can refer to the following answer to resolve your crash.
var statusBarUIView: UIView? {
if #available(iOS 13.0, *) {
let tag = 38482458
if let statusBar = self.keyWindow?.viewWithTag(tag) {
return statusBar
} else {
let statusBarView = UIView(frame: UIApplication.shared.statusBarFrame)
statusBarView.tag = tag
self.keyWindow?.addSubview(statusBarView)
return statusBarView
}
} else {
if responds(to: Selector(("statusBar"))) {
return value(forKey: "statusBar") as? UIView
}
}
return nil
}
这些提到的解决方案对我有用。
These mentioned solutions worked for me.
这篇关于如何在iOS 13中更改状态栏Alpha?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!