问题描述
我有使用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
}
}