如何在 iOS 13 中更改状态栏 Alpha? [英] How can I change Status Bar Alpha in iOS 13?

查看:28
本文介绍了如何在 iOS 13 中更改状态栏 Alpha?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 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',原因:'应用程序调用 -statusBar 或UIApplication 上的 -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屋!

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