How can I change Status Bar Alpha in iOS 13?

前端 未结 3 2112
悲哀的现实
悲哀的现实 2020-12-18 07:25

I want to change the Status Bar Alpha in iOS 13.

let statusBarWindow = UIApplication.shared.value(forKey: \"statusBarWindow\") as? UIWindow
statusBarWindow?.         


        
3条回答
  •  南笙
    南笙 (楼主)
    2020-12-18 07:59

    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.

提交回复
热议问题