如何在全屏 OpenGL ES 应用程序上显示 iPhone/iPad 键盘

发布于 2024-12-02 08:59:27 字数 510 浏览 0 评论 0原文

我正在开发一个有时需要键盘输入的应用程序。我的应用程序使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

删除→记忆 2024-12-09 08:59:27

我无法向您指出一个有效的示例,但我相信您正在寻找的内容就在这里 http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIKeyInput_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UIKeyInput

基本想法是在 UIResponder 对象(例如 UIView)上实现 UIKeyInput 协议。使视图成为第一个响应者,键盘应该自动出现。当用户按下键盘上的按钮时,UIKeyInput 协议为您提供插入字符和删除字符的简单反馈。

这不是工作代码,但它看起来像这样:

@interface MyKeyboardView : UIView <UIKeyInput>
@end

@implementation MyKeyboardView
- (void)insertText:(NSString *)text {
    // Do something with the typed character
}
- (void)deleteBackward {
    // Handle the delete key
}
- (BOOL)hasText {
    // Return whether there's any text present
    return YES;
}
- (BOOL)canBecomeFirstResponder {
    return YES;
}
@end

当附加视图时,使其成为显示键盘的第一响应者

[myView becomeFirstResponder];

或辞职第一响应者以关闭键盘

[myView resignFirstResponder];

编辑:确保您的视图附加到视图层次结构或者这可能不会有任何作用。

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 a UIResponder object, such as a UIView. Make the view the firstResponder and the keyboard should automatically appear. The UIKeyInput 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:

@interface MyKeyboardView : UIView <UIKeyInput>
@end

@implementation MyKeyboardView
- (void)insertText:(NSString *)text {
    // Do something with the typed character
}
- (void)deleteBackward {
    // Handle the delete key
}
- (BOOL)hasText {
    // Return whether there's any text present
    return YES;
}
- (BOOL)canBecomeFirstResponder {
    return YES;
}
@end

when the view is attched, make it the first responder to show the keyboard

[myView becomeFirstResponder];

or resign first responder to dismiss the keyboard

[myView resignFirstResponder];

Edit: make sure your view is attached to the view hierarchy or this probably won't do anything.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文