Created
September 18, 2019 14:31
-
-
Save iosharry/53bcc00643e8237a97d0ce7eacb06134 to your computer and use it in GitHub Desktop.
iOS13 StatusBar Crash Issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
아 아카이브 하려니 똑같은 에러가 발생하네요.
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
공유해 주신 방법이 iPhone XR 에서는 문제 없이 잘 동작 하였는데요. 실제로 배포를 해 보려고 하니
아래와 같은 오류가 발생해서 다른 방법을 검색한 내용을 공유 해 봅니다. (도움이 되면 좋겠네요)
태그 값이 Integer literal '38482458385' overflows when stored into 'Int' 이런 오류가 발생해서 컴파일 오류가 나네요.
그래서, 좀 귀찮기는 하지만, 뷰 컨틀로러에 뷰를 추가하는 방법이 있어서 코멘트 남깁니다.
https://freakycoder.com/ios-notes-13-how-to-change-status-bar-color-1431c185e845
참고한 사이트입니다.
if #available(iOS 13.0, *) {
let app = UIApplication.shared
let statusBarHeight: CGFloat = app.statusBarFrame.size.height
let statusbarView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: statusBarHeight))
statusbarView.backgroundColor = UIColor.red
view.addSubview(statusbarView)
} else {
let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView
statusBar?.backgroundColor = UIColor.red
}
저 사이트의 사용자는 viewDidLoad 에서 사용했다고 하네요. 추가로 탭바 컨트롤러는 viewWillAppear 에 적용해야 한다고....