ios有没有一些API可以手动显示键盘
我有一个自定义视图,我想显示键盘作为我的输入并与其交互。
谢谢大家~
I have a custom view, i want display a keyboard as my input and intercommunicate with it.
thanks guys~
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的自定义视图中,您必须添加一个零大小的 UITextField,然后将您的视图设置为其委托。然后在自定义视图中定义手势识别器(例如单击),并在手势识别器识别事件中将文本字段设置为第一响应者。
一旦您点击视图,键盘就会弹出。然后编写委托方法:
管理与类型化字符串的交互。如果您需要更新用户键盘输入的视图,请不要忘记调用 setNeedsDisplay。
下面的例子有效。当然,您必须在视图控制器中实例化自定义视图。在示例中,只需在键盘中键入一个字母,它就会显示在视图上。
In your custom view you must add a zero-sized UITextField and then set your view as its delegate. Then in your custom view define a gesture recognizer (e.g. a single tap) and in the gesture recognizer recognition event set the text field as first responder.
As soon as you tap the view the keyboard will popup. Then write the delegate method:
to manage the interaction with the typed string. Don't forget to call setNeedsDisplay if you need to update your view on the user keyboard typing.
The example below works. You must instantiate the custom view in your view controller of course. With the example, just type a letter in the keyboard and it will be displayed on the view.
我认为解决方案可以像在类中实现
UIKeyInput
协议一样简单。阅读有关 UIKeyInput 协议参考。
I think the solution could be as simple as implementing the
UIKeyInput
protocol in your class.Read more about the UIKeyInput Protocol Reference.