Skip to content

Instantly share code, notes, and snippets.

@iosharry
Created September 18, 2019 14:31
Show Gist options
  • Save iosharry/53bcc00643e8237a97d0ce7eacb06134 to your computer and use it in GitHub Desktop.
Save iosharry/53bcc00643e8237a97d0ce7eacb06134 to your computer and use it in GitHub Desktop.
iOS13 StatusBar Crash Issue
private var statusBarView: UIView?
if #available(iOS 13.0, *) {
let tag = 38482458385
if let statusBar = UIApplication.shared.keyWindow?.viewWithTag(tag) {
statusBarView = statusBar
} else {
let statusBar = UIView(frame: UIApplication.shared.statusBarFrame)
statusBar.tag = tag
UIApplication.shared.keyWindow?.addSubview(statusBar)
statusBarView = statusBar
}
} else {
statusBarView = UIApplication.shared.value(forKey: "statusBar") as? UIView
}
@iosharry
Copy link
Author

iosharry commented Oct 6, 2019

아 아카이브 하려니 똑같은 에러가 발생하네요.
StatusBar Frame만큼 View를 그려서 addSubView하는 방식이네요. 공유해주셔서 감사합니다.

추가적으로, UIStatusBarManager를 통해서 StatusBar Frame가져올 수 있어요! 아래 코드 참조하시면 좋을 것 같습니다:)

let statusBarFrame = UIApplication.shared.keyWindow?.windowScene?.statusBarManager?.statusBarFrame
let statusBar = UIView(frame: statusBarFrame)
view.addSubView(statusBar)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment