         self.windowLevel = maxWinLevel + 1
     }
 
-    private lazy var adjustWindowLevel: (() -> Void)? = { [weak self] in
+    private lazy var adjustWindowAttributes: ((_ window: UIWindow, _ willShow: Bool) -> Void)? = { [weak self] _, _ in
         self?.setDefaultWindowLevel()
     }
 
-    /// A block to adjust window level so this HUD is displayed appropriately.
+    /// A block to adjust window attributes (e.g., level or make it key) so this HUD
+    /// is displayed appropriately.
     ///
     /// For example, you can adjust the window level so this HUD is always shown
     /// behind the passcode screen to ensure that this HUD is not shown before user

    ///
    /// - Note: By default, window level is set so it appears on the top of the
    /// currently visible window.
    open func adjustWindowLevel(_ callback: @escaping () -> Void) {
        adjustWindowLevel = { [weak self] in
            self?.setDefaultWindowLevel()
            callback()
        }
    }


        let duration = enabled ? self.duration.show : self.duration.hide

        isEnabled = enabled
        adjustWindowAttributes?(window, enabled)
        setNeedsStatusBarAppearanceUpdate()

        if enabled {
            window.isHidden = false

            guard animated else {
                view.alpha = 1
