iPhone 键盘没有文本视图
是否可以在没有文本视图的情况下在 iPhone 应用程序中调出键盘?或者我必须有一个不可见的文本视图?
如果是这样,如何以编程方式创建文本视图,然后调出键盘(用户无需点击文本视图)?我能找到的唯一例子是使用界面生成器..
is it possible to bring up the keyboard in an iphone app without a textview? or will i have to have an invisible textview?
if so, how do you programatically create a textview and then bring up the keyboard (without the user having to tap the textview)? the only examples i can find use interface builder..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
显示键盘的唯一(有效)方法是有一个作为第一响应者的文本字段。
您可以通过在隐藏文本字段上调用
becomeFirstResponder
来隐藏它并以编程方式使其成为第一响应者。您可以通过执行类似的操作以编程方式创建 UITextView (假设 aRect 和视图存在)
The only (valid) way to show the keyboard is to have a textfield that is first responder.
You can hide it and make it first responder programmatically by calling
becomeFirstResponder
on the hidden textfield.You can create a UITextView programmatically by doing something like this (assume aRect and view exist)
UIKeyInput
是您的朋友:示例用法。点击红色视图并查看 Xcode 控制台输出:
UIKeyInput
is your friend:Example usage. Tap the red view and see the Xcode console output:
经过进一步挖掘,我发现了这个。这是非官方的,但我敢打赌它会起作用。
After some more digging, I found this. It's unofficial, but I bet it works.
这个东西的工作方式是通过 NSNotificationCenter 发布/订阅模型。首先您需要使用
addObserver:selector:name:object:
,然后您可以尝试执行 this:但我不确定您会收到什么通知,或者需要注册什么通知才能获取键盘输入的字符值。祝你好运,黑客快乐:)
The way this stuff works is via the NSNotificationCenter publish/subscribe model. First you need to use
addObserver:selector:name:object:
, then you can try doing this:But I'm not sure what notifications you would get, or would need to register for, to get the keyboard typing character values. Good luck and happy hacking :)