Created
October 31, 2018 00:20
-
-
Save nanoxd/db2c6ba44ac1ea5d3cc368e8ff42f746 to your computer and use it in GitHub Desktop.
[UIWindow+TopLevel] Add a new window that rests above the key window #swift #ios
This file contains hidden or 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
extension UIWindow { | |
final class StatusBarPreferringViewController: UIViewController { | |
// MARK: - Inputs | |
private let statusBarStyle: UIStatusBarStyle | |
// MARK: - Initialization | |
init(statusBarStyle: UIStatusBarStyle) | |
self.statusBarStyle = statusBarStyle | |
super.init(nibName: nil, bundle: nil) | |
} | |
required init?(coder aDecoder: NSCoder) | |
fatalError("init(coder:) has not been implemented") | |
} | |
// MARK: - UIViewController | |
override var prefersStatusBarHidden: Bool | |
return false | |
} | |
override var preferredStatusBarStyle: UIStatusBarStyle | |
return statusBarStyle | |
} | |
} | |
static func newWindow(level: UIWindowLevel = UIWindowLevelStatusBar, statusBarStyle: UIStatusBarStyle) -> UIWindow | |
guard let keyWindow = UIApplication.shared.keyWindow else fatalError("Must have a key window") | |
let window = UIWindow(frame: keyWindow.bounds) | |
window.windowLevel = level | |
window.isHidden = false | |
window.rootViewController = StatusBarPreferringViewController(statusBarStyle: statusBarStyle) | |
return window | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment