ios - 如何在 iOS 13 中更改状态栏 Alpha?
问题描述
我想更改 iOS 13 中的状态栏 Alpha。
let statusBarWindow = UIApplication.shared.value(forKey: "statusBarWindow") as? UIWindow
statusBarWindow?.alpha = 0.5
当我尝试这个时,应用程序崩溃(线程 1:信号 SIGABRT)。
解决方案
由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“在 UIApplication 上调用 -statusBar 或 -statusBarWindow 的应用程序:必须更改此代码,因为不再有状态栏或状态栏窗口。在窗口场景中使用 statusBarManager 对象。
您可以参考以下答案来解决您的崩溃问题。
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
}
这些提到的解决方案对我有用。
推荐阅读
- node.js - 无法在 post fetch 中获取 req 对象
- python - Discord.py 发送好友请求
- javascript - 在 Leaflet 中导入多个自定义标记
- amazon-web-services - 访问 AWS Elastic Beanstalk .net 核心应用程序中的 wwwroot 文件夹
- python-3.x - 在 Ubuntu/Vagrant 上升级 Python3
- javafx - 使用代码 javafx 将 GridPane 添加到 ScrollPane
- cakephp - Cakedc 用户插件新表条目
- flutter - 如何创建列表,当您单击其中一个成员时,它会将其移动到收藏夹列表
- python - 如何从另一个执行python文件
- c++ - CMake:如何选择为每个源文件传递哪些包含目录