Skip to content

Instantly share code, notes, and snippets.

@nanoxd
Created October 31, 2018 00:20
Show Gist options
  • Save nanoxd/db2c6ba44ac1ea5d3cc368e8ff42f746 to your computer and use it in GitHub Desktop.
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
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