IQKeyboardManager 这样处理 UITextView 的键盘事件,
键盘出现,走方法
func adjustPosition() {
UITextView 继承自 UIScrollView,
UITextView 通过判断,过滤掉 UITextField,
if let textView = textFieldView as? UIScrollView, textFieldView.responds(to: #selector(getter: UITextView.isEditable)) {
键盘出现调
textView.contentInset
UIView.animate(withDuration: _animationDuration, delay: 0, options: _animationCurve.union(.beginFromCurrentState), animations: { () -> Void in
textView.contentInset = newContentInset
textView.scrollIndicatorInsets = newContentInset
})
实现这么个需求,
上面有一个输入条,TextField,
中间是一个输入框,TextView
-
键盘出现,按钮浮现在键盘之上,
-
键盘消失,按钮恢复在底部

常规思路:
-
键盘出现,把中间 TextView 的高度,缩短
-
键盘消失,恢复中间 TextView 的高度
也可以中间 TextView 的高度不变,
-
键盘出现,调高
textView.contentInset
的 bottom
-
键盘消失,恢复
textView.contentInset
完整代码见
https://github.com/coyingcat/SimpleIQKeyboardManager
本文介绍了如何利用IQKeyboardManager库来处理UITextField和UITextView的键盘显示与隐藏事件,特别是在有多个输入组件时如何调整布局。当键盘弹出,会调整TextView的contentInset以使底部按钮浮于键盘上方;键盘收起时,恢复contentInset。具体实现和代码参考可在GitHub上的SimpleIQKeyboardManager项目中查看。
3050

被折叠的 条评论
为什么被折叠?



