问题描述
我在我的应用程序中放置了一个数字键盘,用于在文本视图中输入数字,但为了输入数字,我必须单击文本视图.一旦我这样做了,常规键盘就会出现,这是我不想要的.
I put a numeric keypad in my app for inputing numbers into a text view, but in order to input numbers I have to click on the text view. Once I do so, the regular keyboard comes up, which I don't want.
如何完全禁用键盘?非常感谢任何帮助.
How can I disable the keyboard altogether? Any help is greatly appreciated.
推荐答案
UITextField 的 inputView 属性默认为 nil,这意味着显示标准键盘.
The UITextField's inputView property is nil by default, which means the standard keyboard gets displayed.
如果你给它分配一个自定义输入视图,或者只是一个虚拟视图,那么键盘不会出现,但闪烁的光标仍然会出现:
If you assign it a custom input view, or just a dummy view then the keyboard will not appear, but the blinking cursor will still appear:
UIView* dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
myTextField.inputView = dummyView; // Hide keyboard, but show blinking cursor
如果您想隐藏键盘和闪烁的光标,请使用以下方法:
If you want to hide both the keyboard and the blinking cursor then use this approach:
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
return NO; // Hide both keyboard and blinking cursor.
}
这篇关于禁用 UITextField 键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!