How to observe UIKeyboardLayoutGuide.layoutFrame changes

7 hours ago 1
ARTICLE AD BOX

I want to observe the changes in UIKeyboardLayoutGuide.layoutFrame, but using the KVO method, the code inside the layoutObservation block is only called once (when the keyboard is first shown).

guard #available(iOS 15.0, *), let window = UIApplication.shared.connectedScenes .compactMap({ $0 as? UIWindowScene }) .first(where: { $0.activationState == .foregroundActive })? .keyWindow, let rootView = window.rootViewController?.view else { return nil } let guide = rootView.keyboardLayoutGuide guide.followsUndockedKeyboard = true let layoutObservation = guide.observe(\.layoutFrame, options: [.initial, .new]) { [weak self] guide, _ in // This is called only once; when the keyboard is shown print("layoutObservation...") }
Read Entire Article