iOS自定义键盘和系统键盘切换且文本输入框一直得到焦点

UITextView用来进行文本输入。
方法becomeFirstResponder和resignFirstResponder能够用来进行弹出系统键盘和收下系统键盘。this

弹出系统键盘,文本输入框得到焦点。收下系统键盘,文本输入框失去焦点。那么,问题来了。spa

某个条件下,如点击界面上的某个按钮,展现自定义键盘。再次点击,切换到系统键盘。
先收下系统键盘,再展现自定义键盘。好比移动自定义键盘View的Frame.Y。但这时由于收下系统键盘,本文输入框失去焦点。
虽然展现了自定义键盘。但用户体验很很差。光标没有闪动。自定义键盘输入的内容没法准确插入到文本输入框里。

解决方法:(见iOS开发文档)ci

@property(readwrite, retain) UIView *inputView开发

If the value in this property is nil, the text view displays the standard system keyboard when it becomes first responder. Assigning a custom view to this property causes that view to be presented instead.文档

The default value of this property is nil.input

 

这个属性就是说
1.为nil时展现系统键盘。
2.为自定义View时展现自定义键盘。

注意要刷新。it

- (void)reloadInputViewsclass

You can use this method to refresh the custom input view or input accessory view associated with the current object when it is the first responder. The views are replaced immediately—that is, without animating them into place. If the current object is not the first responder, this method has no effect.用户体验

完美解决问题。
文本输入框一直得到焦点。自定义键盘和系统键盘自由切换。iOS开发

相关文章
相关标签/搜索