How to display the iPhone/iPad keyboard over a full screen OpenGL ES app

后端 未结 1 928
囚心锁ツ
囚心锁ツ 2021-02-07 05:05

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 kno

相关标签:
1条回答
  • 2021-02-07 05:34

    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.

    0 讨论(0)
提交回复
热议问题