iOS隐藏默认键盘并打开自定义键盘 [英] iOS hide default keyboard and open custom keyboard
问题描述
我有一个UITextview
,当用户点击UITextview
时,我需要隐藏默认键盘.为此,我做了
I have an UITextview
, when user taps on UITextview
i need to hide the default keyboard. For that i have done,
[myTextView setEditable: NO];
因此未显示键盘,这里我用UIButton
创建了一个自定义视图,当用户点击UITextView
时,我需要显示此UIView
,为此我已经完成了
So the keyboard is not shown, here i have created an Custom View with UIButton
, i need to show this UIView
when the user taps on UITextView
, for that i have done,
textViewDidBeginEditing{
//Here i have added UIView as subview
}
但是由于以下原因,该方法无法正常工作
But this method is not working because of,
[myTextView setEditable: NO];
,当用户单击UIView
推荐答案
您应该使用resignFirstResponder
而不是将UITextView设置为不可编辑.这将隐藏系统键盘.
You should be using resignFirstResponder
instead of setting the UITextView to not editable. This will hide the system keyboard.
[myTextView resignFirstResponder];
如果要为键盘使用其他视图,则系统提供了一个视图,然后在UITextView上将inputView
设置为要用于代替系统键盘的自定义视图.
If you want to use a different view for the keyboard then the system provided one then set inputView
on the UITextView to the custom view you want to be used in place of the system keyboard.
myTextView.inputView = myCustomView;
这篇关于iOS隐藏默认键盘并打开自定义键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!