如何让ios键盘手动出现?
我有一个自定义视图,它将充当文本字段,另一个自定义视图帽将充当其键盘。我本来打算实现 uikeyinput 协议,但由于它是自定义键盘,它无法通过 uikeyinput 向其委托发送消息,所以我想我也可以制作一个自定义协议。 将文本字段设为第一响应者后,如何对键盘进行编程,使其在有人单击文本字段时出现?
I have a custom view which will act as a text field and another custom view hat acts as its keyboard. I was planning on implementing uikeyinput protocol, but since its a custom keyboard, it can't send messages to its delegate through uikeyinput, so I thought I might as well make a custom protocol as well.
After making the text field first responder, how do I program the keyboard to appear when someone clicks the text field?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当文本字段成为第一响应者时,它会自动调出键盘。要使键盘出现,只需发送
[textFieldBecomeFirstResponder]
。When a text field becomes first responder, it'll automatically bring up the keyboard. To make the keyboard come up, just send
[textField becomeFirstResponder]
.在自定义视图类标头中声明属性
inputView
:不要合成它。相反,在自定义视图类中显式实现 getter 以返回自定义键盘视图。一旦您的视图成为第一响应者,Cocoa 就会自动读取此属性以检查您的视图是否需要自定义键盘。它甚至可以为键盘设置动画。
请参阅 UIResponder。
Declare the property
inputView
in your custom view class header:Don't synthesize it. Instead, explicitly implement the getter in your custom view class to return your custom keyboard view. Once your view becomes first responder Cocoa automatically reads this property to check if your view needs a custom keyboard. It even animates the keyboard in.
See the documentation for UIResponder.