League2eb

原本是這樣寫,但訪問的時候會有機率性閃退

1
2
3
4
5
6
var statusBarView: UIView? {
if responds(to: Selector(("statusBar"))) {
return value(forKey: "statusBar") as? UIView
}
return nil
}

並且給出下面這段Error

新寫法

1
2
3
4
5
6
7
8
9
10
11
var statusBarView: UIView? {
if #available(iOS 13.0, *) {
let statusBarView = UIView(frame: UIApplication.shared.statusBarFrame)
return statusBarView
} else {
guard let statusBarView = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView else {
return nil
}
return statusBarView
}
}

特別感謝MARK SU用心記錄
此篇特別感謝,並筆記


 評論