I'm currently developing an OpenGL ES game for the iPhone and iPod touch.
I was wondering how I can easily pull up the UIKeyboard? Is there an official, documented possibility to pull up a UIKeyboard without using a UITextField of UITextView?
I'm currently developing an OpenGL ES game for the iPhone and iPod touch.
I was wondering how I can easily pull up the UIKeyboard? Is there an official, documented possibility to pull up a UIKeyboard without using a UITextField of UITextView?
It's not "officially" possible - you can't access the UIKeyboard object at all while staying within Apple's guidelines.
Creating an invisible UITextField, then calling [textField becomeFirstResponder]
would do the job - you could even subclass UITextField first, then override the delegate method textField:shouldChangeCharactersInRange:
to redirect the text input to where you want it to go.
If you subclass UIResponder, and declare the UIKeyInput protocol, the keyboard will appear when you become the firstResponder.
See the UIKeyInput protocol here.
One thing that tripped me up is that you'll need to override the canBecomeFirstResponder message.
It is indeed possible. I had myself struggled a lot with this. UIKeyInput protocol can be used to pull a keyboard without using a UITextField or UITextView. However it is only available in iOS 3.2 and above. Here is a tutorial on that.
Hope that helps.
I displayed the keyboard without any visible UITextField by positioning my textfield's frame out of the visible screen:
#define TEXT_FRAME -50,-50,0,0
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(TEXT_FRAME)];
When I set the "first responder" the keyboard becomes visible without any visible input area:
// show the keyboard
[self.textField becomeFirstResponder];
I later dropped the idea. However, I don't know its conformance to the Apple guidelines.
I haven't tried it but http://www.cocoadev.com/index.pl?UIKeyboard shows some code that looks like it should work.