ARTICLE AD BOX
With the following piece of code, we can have a pretty good idea of when the soft keyboard becomes visible/invisible:
let showingObserver = NotificationCenter.default.addObserver( forName: UIResponder.keyboardWillShowNotification, object: nil, queue: .main ) { [weak self] _ in // keyboard is (about to be) shown } let hidingObserver = NotificationCenter.default.addObserver( forName: UIResponder.keyboardWillHideNotification, object: nil, queue: .main ) { [weak self] _ in // keyboard is (about to be) hidden }But this code only works for docked keyboard. For other types of keyboards, such as undocked, split, or floating, these notifications aren't fired. UIResponder.keyboardWillChangeFrameNotification is fired for these other types of keyboards, but it doesn't provide useful information to distinguish between the keyboard being shown/hidden. Is there any other reliable way for this feature to work for all the soft keyboard types? I know there is a relatively new class (UIKeyboardLayoutGuide) that works for all the keyboard types, and its documentation says: "A layout guide that represents the space the keyboard occupies in your app’s layout." I was wondering if this new class can provide an API for detecting keyboard visibility!
1,12914 silver badges37 bronze badges
Explore related questions
See similar questions with these tags.
