[在iPhone 7中使用statusBarwindow时出现NSInternalInconsistencyencyException异常

问题描述 投票:0回答:1

运行我的项目iPhone 7 plus时出现异常“ NSInternalInconsistencyException”。

让statusBarWindow = UIApplication.shared.value(forKey:“ statusBarWindow”)为! UIView让statusBar = statusBarWindow.subviews [0]为! UIViewstatusBar.backgroundColor = UIColor(红色:42.0 / 255.0,绿色:42.0 / 255.0,蓝色:40.0 / 255.0,alpha:1.0)

这是一个例外。“ NSInternalInconsistencyException”,原因:“ UIApplication上名为-statusBar或-statusBarWindow的应用程序:必须更改此代码,因为不再有状态栏或状态栏窗口。请在窗口场景上使用statusBarManager对象。'

谁能帮我修复它。

ios xcode screen device statusbar
1个回答
0
投票

现在,如果您使用的是iOS 13的SDK,则不建议使用statusBarWindow的KVO。

为了设置状态栏的颜色,您需要使用Objective-C中的statusBarManager,如下所示:

UIView *statusBar = [[UIView alloc]initWithFrame:[UIApplication sharedApplication].keyWindow.windowScene.statusBarManager.statusBarFrame] ; [[UIApplication sharedApplication].keyWindow addSubview:statusBar]; statusBar.backgroundColor = \*Your color*\;

© www.soinside.com 2019 - 2024. All rights reserved.