@@ -13,7 +13,7 @@ import UIKit
1313
1414public class ProgressHUD : UIView {
1515
16- var main = UIApplication . shared . windows . first ?? UIWindow ( )
16+ var main : UIWindow !
1717
1818 // Banner properties
1919 var viewBanner : UIToolbar ?
@@ -91,7 +91,7 @@ extension ProgressHUD {
9191
9292 removeDelayTimer ( )
9393
94- setupNotifications ( )
94+ setupWindow ( )
9595 setupBackground ( interaction)
9696 setupToolbar ( )
9797 setupStatus ( text)
@@ -124,6 +124,7 @@ extension ProgressHUD {
124124 }
125125
126126 setupSizes ( text, animation)
127+ setupNotifications ( )
127128 setupPosition ( )
128129 displayHUD ( )
129130 }
@@ -170,7 +171,17 @@ extension ProgressHUD {
170171 }
171172}
172173
173- // MARK: - Background View
174+ // MARK: - Window
175+ extension ProgressHUD {
176+
177+ private func setupWindow( ) {
178+ if ( main == nil ) {
179+ main = UIApplication . shared. windows. first
180+ }
181+ }
182+ }
183+
184+ // MARK: - Background
174185extension ProgressHUD {
175186
176187 private func removeBackground( ) {
@@ -455,19 +466,17 @@ extension ProgressHUD {
455466 }
456467 }
457468
458- private func keyboardHeight( ) -> CGFloat {
459- if let keyboardWindowClass = NSClassFromString ( " UIRemoteKeyboardWindow " ) ,
460- let inputSetContainerView = NSClassFromString ( " UIInputSetContainerView " ) ,
461- let inputSetHostView = NSClassFromString ( " UIInputSetHostView " ) {
462-
463- for window in UIApplication . shared. windows {
464- if window. isKind ( of: keyboardWindowClass) {
465- for firstSubView in window. subviews {
466- if firstSubView. isKind ( of: inputSetContainerView) {
467- for secondSubView in firstSubView. subviews {
468- if secondSubView. isKind ( of: inputSetHostView) {
469- return secondSubView. frame. size. height
470- }
469+ func keyboardHeight( ) -> CGFloat {
470+ let windows = UIApplication . shared. windows
471+ for window in windows {
472+ for view in window. subviews {
473+ if String ( describing: type ( of: view) ) . hasPrefix ( " UIInputSetContainerView " ) {
474+ for subview in view. subviews {
475+ if String ( describing: type ( of: subview) ) . hasPrefix ( " UIInputSetHostView " ) {
476+ let screenRect = UIScreen . main. bounds
477+ let keyboardRect = window. convert ( subview. frame, to: nil )
478+ if keyboardRect. intersects ( screenRect) {
479+ return subview. frame. height
471480 }
472481 }
473482 }
0 commit comments