From 2f7b392e96bed6750e8b5e0101e85fe6406eda79 Mon Sep 17 00:00:00 2001 From: toshi0383 Date: Fri, 9 Dec 2022 17:12:01 +0900 Subject: [PATCH] fix: ignore floating keyboard --- .../KeyboardLayoutGuide.swift | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Sources/KeyboardLayoutGuide/KeyboardLayoutGuide.swift b/Sources/KeyboardLayoutGuide/KeyboardLayoutGuide.swift index d12a2c4..ef585da 100644 --- a/Sources/KeyboardLayoutGuide/KeyboardLayoutGuide.swift +++ b/Sources/KeyboardLayoutGuide/KeyboardLayoutGuide.swift @@ -179,7 +179,7 @@ extension UILayoutGuide { extension Notification { var keyboardHeight: CGFloat? { - guard let keyboardFrame = userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else { + guard let keyboardEndFrame = userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else { return nil } @@ -187,7 +187,21 @@ extension Notification { return 0.0 } - let keyboardMinY = keyboardFrame.cgRectValue.minY + let keyboardMinY = keyboardEndFrame.cgRectValue.minY + + let isLikelyFloating: Bool = { + if keyboardMinY == 0 { return true } + + guard let keyboardBeginFrame = userInfo?[UIResponder.keyboardFrameBeginUserInfoKey] as? NSValue else { + return false + } + + return keyboardBeginFrame.cgRectValue.minY == 0 + }() + + if isLikelyFloating { + return nil + } // Weirdly enough UIKeyboardFrameEndUserInfoKey doesn't have the same behaviour // in ios 10 or iOS 11 so we can't rely on v.cgRectValue.width