网上找了很多,都不是自己想要的
func isProtraitLockOn() -> Bool {
let app = UIApplication.shared
var foregroundView: UIView?
var cls: UIView.Type?
let statusBar: UIView? = app.value(forKeyPath: "statusBar") as? UIView
guard statusBar != nil else {
return false
}
foregroundView = statusBar?.value(forKeyPath: "foregroundView") as? UIView
if foregroundView == nil {
let statusBarView = statusBar!.value(forKeyPath: "statusBar") as? UIView
if statusBarView != nil {
foregroundView = statusBarView!.value(forKeyPath: "foregroundView") as? UIView
}
}
cls = NSClassFromString("_UIStatusBarImageView") as? UIView.Type
var isOn = false
for child in foregroundView?.subviews ?? [] {
if let cls1 = cls, child.isKind(of: cls1), child.frame.size.equalTo(CGSize(width: 11.5, he