关键是得到新的y点,这样就可以得到输入框的新位置。
keyboardWillChangeFrame可以监控键盘的新位置,键盘的y减去两倍的输入框值就是输入框的新位置y
效果如图所示
//动态监听键盘
@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
}
}