'statusBarFrame' was deprecated in iOS 13.0: Use the statusBarManager property of the window scene !
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公众号:MindDraft
➤博主域名:https://www.zengqiang.org
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:https://www.cnblogs.com/strengthen/p/12109327.html
➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
由于未捕获的异常“ NSInternalInconsistencyException”而终止应用程序,原因:“在UIApplication上名为-statusBar或-statusBarWindow的应用程序:必须更改此代码,因为不再有状态栏或状态栏窗口。而是在窗口场景上使用statusBarManager对象。”
但是目前尚不清楚应如何使用它来更改颜色,因为keyWindow?.windowScene?.statusBarManager
它似乎不包含与之相关的任何内容。
1 //MARK: 扩展UIApplication 2 extension UIApplication { 3 var statusBarUIView: UIView? { 4 5 if #available(iOS 13.0, *) { 6 let tag = 3848245 7 8 let keyWindow = UIApplication.shared.connectedScenes 9 .map({$0 as? UIWindowScene}) 10 .compactMap({$0}) 11 .first?.windows.first 12 13 if let statusBar = keyWindow?.viewWithTag(tag) { 14 return statusBar 15 } else { 16 let height = keyWindow?.windowScene?.statusBarManager?.statusBarFrame ?? .zero 17 let statusBarView = UIView(frame: height) 18 statusBarView.tag = tag 19 statusBarView.layer.zPosition = 999999 20 21 keyWindow?.addSubview(statusBarView) 22 return statusBarView 23 } 24 25 } else { 26 27 if responds(to: Selector(("statusBar"))) { 28 return value(forKey: "statusBar") as? UIView 29 } 30 } 31 return nil 32 }