iOS 14键盘响应器不再起作用

问题描述


在具有IOS 14的设备上,该设备检测到“键盘高度”以偏移/将填充设置为TextField的内容,并且下面的其他内容不再起作用。 IOS 14会自动执行此操作,但只会对文本字段执行此操作,而不会对文本字段下方的按钮执行此操作。 但我希望它像这样工作,使“下一个”按钮可见:

Pre Show Keyboard

Keyboard showing

IOS 14更改

在IOS 14中,您可以使用此命令停止偏移量

.ignoresSafeArea(.keyboard,edges: .bottom)

但是KeyboardResponder不能再在IOS 14上使用,所以我不能在内容中添加填充或偏移量。

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
    }
}

有人可以帮助更新Responder与IOS 14一起使用吗? 巴斯蒂

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)