@@ -63,10 +63,17 @@ open class KeyboardLayoutGuide: UILayoutGuide {
63
63
// Observe keyboardWillChangeFrame notifications
64
64
notificationCenter. addObserver (
65
65
self ,
66
- selector: #selector( keyboardWillChangeFrame ( _: ) ) ,
66
+ selector: #selector( adjustKeyboard ( _: ) ) ,
67
67
name: UIResponder . keyboardWillChangeFrameNotification,
68
68
object: nil
69
69
)
70
+ // Observe keyboardWillHide notifications
71
+ notificationCenter. addObserver (
72
+ self ,
73
+ selector: #selector( adjustKeyboard ( _: ) ) ,
74
+ name: UIResponder . keyboardWillHideNotification,
75
+ object: nil
76
+ )
70
77
}
71
78
72
79
internal func setUp( ) {
@@ -100,7 +107,7 @@ open class KeyboardLayoutGuide: UILayoutGuide {
100
107
}
101
108
102
109
@objc
103
- private func keyboardWillChangeFrame ( _ note: Notification ) {
110
+ private func adjustKeyboard ( _ note: Notification ) {
104
111
if var height = note. keyboardHeight, let duration = note. animationDuration {
105
112
if #available( iOS 11 . 0 , * ) , usesSafeArea, height > 0 , let bottom = owningView? . safeAreaInsets. bottom {
106
113
height -= bottom
@@ -142,10 +149,15 @@ extension Notification {
142
149
guard let keyboardFrame = userInfo ? [ UIResponder . keyboardFrameEndUserInfoKey] as? NSValue else {
143
150
return nil
144
151
}
145
- // Weirdly enough UIKeyboardFrameEndUserInfoKey doesn't have the same behaviour
146
- // in ios 10 or iOS 11 so we can't rely on v.cgRectValue.width
147
- let screenHeight = UIApplication . shared. keyWindow? . bounds. height ?? UIScreen . main. bounds. height
148
- return screenHeight - keyboardFrame. cgRectValue. minY
152
+
153
+ if name == UIResponder . keyboardWillHideNotification {
154
+ return 0.0
155
+ } else {
156
+ // Weirdly enough UIKeyboardFrameEndUserInfoKey doesn't have the same behaviour
157
+ // in ios 10 or iOS 11 so we can't rely on v.cgRectValue.width
158
+ let screenHeight = UIApplication . shared. keyWindow? . bounds. height ?? UIScreen . main. bounds. height
159
+ return screenHeight - keyboardFrame. cgRectValue. minY
160
+ }
149
161
}
150
162
151
163
var animationDuration : CGFloat ? {
0 commit comments