Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pull up a UIKeyboard without a UITextField or 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?

like image 982
Kriem Avatar asked Sep 03 '09 21:09

Kriem


4 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.

like image 198
john Avatar answered Nov 02 '22 14:11

john


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.

like image 41
Tim Avatar answered Nov 02 '22 16:11

Tim


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.

like image 3
Bani Uppal Avatar answered Nov 02 '22 15:11

Bani Uppal


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.

like image 1
Oguz Kupusoglu Avatar answered Nov 02 '22 15:11

Oguz Kupusoglu