iOS 键盘上方输入框被遮挡的问题

关键是得到新的y点,这样就可以得到输入框的新位置。
keyboardWillChangeFrame可以监控键盘的新位置,键盘的y减去两倍的输入框值就是输入框的新位置y
效果如图所示


Simulator Screen Shot - iPhone 12 - 2022-01-10 at 09.28.21.png
Simulator Screen Shot - iPhone 12 - 2022-01-10 at 09.28.27.png
   //动态监听键盘
    @objc func keyboardWillChangeFrame(_ notification:NSNotification)  {
        let info = notification.userInfo
        let keyboardRect = (info?[UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue
        var blueRect = self.v.bottomToolBar.frame
        blueRect.origin.y = keyboardRect.origin.y - blueRect.size.height * 2
        Logger.log("键盘y\(keyboardRect.origin.y)==\(blueRect.origin.y)")
        UIView.animate(withDuration: 0.3) {
            self.v.bottomToolBar.frame = blueRect
        }
    }

你可能感兴趣的:(iOS 键盘上方输入框被遮挡的问题)