IOS 14 Keyboard Responder not working anymore

Viewed 466

On a device with IOS 14 detecting the Keyboard Height to offset / set padding to the content of the TextField AND other content below isn't working anymore. IOS 14 does this automatically but only to the Textfield and not to Buttons below the textfields. But I want it to work like this, making the "next" Button visible:

Pre Show Keyboard

Keyboard showing

IOS 14 changes

In IOS 14 you can stop the offset with this command

.ignoresSafeArea(.keyboard, edges: .bottom)

but the KeyboardResponder isn't working on IOS 14 anymore, so I can't add padding or an offset to the content.

final class KeyboardResponder: ObservableObject {
    
    private var notificationCenter: NotificationCenter
    @Published private(set) var currentHeight: CGFloat = 0
    
    init(center: NotificationCenter = .default) {
        notificationCenter = center
        notificationCenter.addObserver(self, selector: #selector(keyBoardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
        notificationCenter.addObserver(self, selector: #selector(keyBoardWillHide(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil)
    }

    deinit {
        notificationCenter.removeObserver(self)
    }

    @objc func keyBoardWillShow(notification: Notification) {
        if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
            print("keyboardSizeChange \(keyboardSize.height)")
            currentHeight = keyboardSize.height
        }
    }

    @objc func keyBoardWillHide(notification: Notification) {
        currentHeight = 0
    }
}

Can anybody help update the Responder to work with IOS 14? Basti

0 Answers
Related