如何在全屏 OpenGL ES 应用程序上显示 iPhone/iPad 键盘
我正在开发一个有时需要键盘输入的应用程序。我的应用程序使用 OpenGL ES 进行显示,并且我有自己的图形框架,可以显示文本字段,并且知道如何管理光标和渲染文本。该代码在具有物理键盘的其他平台(例如 Windows 和 OS X)上运行良好。
要让我的应用程序的 iOS 版本正常工作,我所需要的就是能够以编程方式上下移动键盘,并获取密钥将用户的事件按到我的视图中,以便我可以将它们路由到我的框架自己的事件系统中。
我看到这个问题,但是我无法使那里描述的解决方案起作用。不确定是因为我做错了什么,还是因为它不适用于当前的 iOS 版本。
编辑:指出一个带有源代码的工作应用程序会很有帮助,该应用程序以编程方式创建任何 UI 元素并将其显示在 GL ES 屏幕顶部。我想如果我理解了那部分,我就能弄清楚剩下的部分。
I'm working on an app that at some point requires keyboard input. My app uses OpenGL ES for display, and I have my own graphics framework that can display a text field, and knows how to manage the cursor and render text. This code works great on other platforms that have a physical keyboard, like Windows and OS X.
All I need to get the iOS version of my app working is to be able to bring the keyboard up and down programmatically, and also to get the key press events from the user into my view so that I can then route them into my framework's own event system.
I saw this question, but I could not make the solution depicted there work. Not sure if it is because I'm doing something wrong, or because it doesn't work on current iOS releases.
EDIT: It would be as helpful to be pointed at a working app with source code that creates any UI element programmatically and displays it on top of a GL ES screen. I think I can figure the rest out if I get that part understood.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法向您指出一个有效的示例,但我相信您正在寻找的内容就在这里 http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIKeyInput_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UIKeyInput
基本想法是在
UIResponder
对象(例如UIView
)上实现UIKeyInput
协议。使视图成为第一个响应者,键盘应该自动出现。当用户按下键盘上的按钮时,UIKeyInput
协议为您提供插入字符和删除字符的简单反馈。这不是工作代码,但它看起来像这样:
当附加视图时,使其成为显示键盘的第一响应者
或辞职第一响应者以关闭键盘
编辑:确保您的视图附加到视图层次结构或者这可能不会有任何作用。
I can't point you at a working example, but I believe what you're looking for is here http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIKeyInput_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UIKeyInput
The basic idea is that you implement the
UIKeyInput
protocol on aUIResponder
object, such as aUIView
. Make the view the firstResponder and the keyboard should automatically appear. TheUIKeyInput
protocol gives you simple feedback for inserting a character and deleting a character when the user presses buttons on the keyboard.This isn't working code, but it would look something like this:
when the view is attched, make it the first responder to show the keyboard
or resign first responder to dismiss the keyboard
Edit: make sure your view is attached to the view hierarchy or this probably won't do anything.