如何在全屏OpenGL ES应用程序上显示iPhone / iPad键盘 [英] How to display the iPhone/iPad keyboard over a full screen OpenGL ES app

查看:194
本文介绍了如何在全屏OpenGL ES应用程序上显示iPhone / iPad键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,有时需要键盘输入。我的应用程序使用OpenGL ES显示,我有我自己的图形框架,可以显示一个文本字段,并知道如何管理光标和渲染文本。此代码在其他具有物理键盘的平台(如Windows和OS X)上效果非常好。

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.

我需要获得iOS版本的应用程序以编程方式上下键盘,还可以将用户的按键事件传递到我的视图中,这样我可以将它们路由到我的框架自己的事件系统中。

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.

我看到此问题 ,但我不能使解决方案描述有工作。不确定是否是因为我做错了事,或者因为它在当前的iOS版本上不起作用。

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.

编辑:这将有助于指向在一个工作的应用程序与源代码创建任何UI元素以编程方式,并显示在GL ES屏幕的顶部。

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.

推荐答案

我不能指出一个工作示例,但我相信您要查找的是 http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIKeyInput_Protocol/Reference/Reference.html#//apple_ref/occ/intf/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

基本思想是在 UIResponder UIKeyInput $ c>对象,例如 UIView 。使视图firstResponder和键盘应该会自动出现。 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

响应者显示键盘

[myView becomeFirstResponder];

或退出第一个回应者关闭键盘

or resign first responder to dismiss the keyboard

[myView resignFirstResponder];

编辑:确保您的视图附加到视图层次结构,否则这可能不会做任何事情。

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

这篇关于如何在全屏OpenGL ES应用程序上显示iPhone / iPad键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆