如何更改此不推荐使用的代码? flutter_inappwebview

问题描述

我有使用inappview依赖项的代码,但抛出此警告: 'statusBarStyle'的设置在iOS 9.0中已弃用:使用-[UIViewController preferredStatusBarStyle]

如何将不推荐使用的代码转换为新版本的代码

    public func hide() {
    isHidden = true
    
    // Run later to avoid the "took a long time" log message.
    dispatchQueue.main.async(execute: {() -> Void in
        self.presentingViewController?.dismiss(animated: true,completion: {() -> Void in
            self.tmpWindow?.windowLevel = UIWindow.Level(rawValue: 0.0)
            UIApplication.shared.delegate?.window??.makeKeyAndVisible()
            if self.prevIoUsstatusBarStyle != -1 {
                UIApplication.shared.statusBarStyle = UIStatusBarStyle(rawValue: self.prevIoUsstatusBarStyle)!
            }
        })
    })
}

解决方法

在viewController中重写preferredStatusBarStyle方法,并调用setNeedsStatusBarAppearanceUpdate方法以更新状态栏的外观。您还可以将previousStatusBarStyle属性设置为可选,以便可以使用if-let来检查其可用性。如果您想隐藏状态栏,请覆盖prefersStatusBarHidden方法以返回true。

class YourViewController : UIViewController {
    var previousStatusBarStyle: UIStatusBarStyle?

    public func hide() {
        isHidden = true

        // Run later to avoid the "took a long time" log message.
        DispatchQueue.main.async(execute: {() -> Void in
            self.presentingViewController?.dismiss(animated: true,completion: {() -> Void in
                self.tmpWindow?.windowLevel = UIWindow.Level(rawValue: 0.0)
                UIApplication.shared.delegate?.window??.makeKeyAndVisible()
                if let statusBarStyle = self.previousStatusBarStyle {
                    self.setNeedsStatusBarAppearanceUpdate()
                }
            })
        })
    }
    

    // In your view controller's scope
    override var preferredStatusBarStyle: UIStatusBarStyle {
        return previousStatusBarStyle ?? .default
    }

}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...