How to pull up a UIKeyboard without a UITextField or UITextView?

By | January 12, 2018
Questions:

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?

Answers:

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.

Questions:
Answers:

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.

Questions:
Answers:

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.

Questions:
Answers:

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.

Questions:
Answers:

I haven’t tried it but http://www.cocoadev.com/index.pl?UIKeyboard shows some code that looks like it should work.

Leave a Reply

Your email address will not be published. Required fields are marked *