我可以通过编程方式触发“切换到数字键盘”吗? iPhone 键盘上的按钮
我想找到一种以编程方式触发选择器的方法,使 iPhone 键盘从字母切换到数字。我知道我可以切换键盘类型,但我想知道是否有办法在不切换键盘类型的情况下执行此操作。
I want to find a way to programmatically fire the selector that causes the iPhone keyboard to switch from letters to numbers. I am aware that I can switch the keyboard type, but I want to know if there is a way to do this without switching the keyboard type.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您不能以编程方式切换关键平面(字母关键平面到数字关键平面到符号关键平面),至少不能以任何公开支持的方式。正如您所提到的,您可以更改第一响应者的键盘类型或文本输入特征的外观,但这与在不同键盘平面之间切换不同,后者只有用户才能执行。
You cannot switch keyplanes (alphabetic keyplane to numeric keyplane to symbol keyplane) programatically, at least not in any way that is publicly supported. As you mentioned, you can change the keyboard type or appearance of the text input traits of the first responder, but this is different than switching between the different keyplanes, which only the user should be able to do.
只是一个解决方法:
当您想要在编辑 UITextField 时更改活动键盘的键平面(例如从字母表更改为数字键盘)时,首先将新值设置为文本字段的 KeyboardType 属性,然后发送 resignFirstResponder 消息,最后向文本字段发送BecomeFirstResponder 消息。例如
Swift:
希望有帮助;-D
Just a workaround:
When you want to change the keyplane of an active keyboard like from alphabet to number pad while editing an UITextField, first set the new value to the keyboardType property of the textfield, next send a resignFirstResponder, finally a becomeFirstResponder message to the textfield. E.g.
Swift:
Hope it helps ;-D
对于自定义切换键盘类型,您可以使用键盘的accessoryView
使键盘accessoryView用于类型切换的代码...(希望被剪断代码是可以理解的)
For custom switching keyboard types you can use accessoryView of Keyboard
Code to make the keyboard accessoryView for type switching... (hopefully the snipped code is understandable)
看看这个:
检查我评论的地方“c this care full”
这将帮助您以编程方式切换键盘。
Have a look at this:
Check where I commented "c this care fully"
This will help you to switch keyboards programmatically.
也许
会有帮助。它以数字模式启动键盘,您可以切换回字母模式。
Maybe
will help. It starts the keyboard in numeric mode and you can switch back to alphabet.