iPhone keyboard
I was wondering how does the iPhone keyboard work.
I figure it probably belongs to a view and is usually sent a message by a field and pops up like a drawer when it receives the message.
What view does it belong to?
My game view is inherited from UIView but I'm running OpenGL, so is it possible to have a keyboard pop up over an OpenGL view?
Thanks again.
I figure it probably belongs to a view and is usually sent a message by a field and pops up like a drawer when it receives the message.
What view does it belong to?
My game view is inherited from UIView but I'm running OpenGL, so is it possible to have a keyboard pop up over an OpenGL view?
Thanks again.
Add a UITextField, then send a becomeFirstResponder message to it so as to popup the keyboard immediately.
The crashlanding sample code shows this working.
The crashlanding sample code shows this working.
Yeah, it works fine over GL views for me.
... I may be way off here, so I don't mean to add dis-information, but for some reason I don't get the impression that it belongs to any view in particular, but rather the system itself, somehow. It seems to operate above everything.
... I may be way off here, so I don't mean to add dis-information, but for some reason I don't get the impression that it belongs to any view in particular, but rather the system itself, somehow. It seems to operate above everything.
It belongs to the instance of UIWindow. UIWindow keeps track of the first responder. And there are a few other clues in UIWindow.h, as well, including the definitions of all of the UIKeyboard*Notifications.
Yeah, but it seems like it is a special member since it seems to draw with a much higher priority than say, an underlying GL view. Just a goofy side-ways observation on my part from all the hundreds of hours of watching things during development.
Of course it can have a higher priority, you have one UIWindow instance and every single thing you see on your screen is a subview of that UIWindow. The UIWindow is the top of any view hierarchy on the iPhone, so it has the ability to insert any view anywhere it wants.
Sorry, I understand that. I've just noticed some subtle inconsistencies with how things seem to be timed to draw on iPhone from time to time. Maybe has to do with scheduling with the PVR hardware.
Anyway, yeah, it belongs to the UIWindow.
Anyway, yeah, it belongs to the UIWindow.
The stacking of levels takes precedence over the stacking of windows within each level. That is, even the bottom window in a level obscures the top window of the next level down. Levels are listed in order from lowest to highest.
- Found this in the documentation for UIWindow. Is that what you were unsure about Jake?
Also, strangely, the UIWindow inherits the UIView. My view was inheriting from UIView so I changed it to UIWindow, since it's up the hierarchy. It compiles fine but I'm not messing with it anymore tonight. I'll see if I can figure out how to get a keyboard up tomorrow. Thanks everyone for your inputs.
- Found this in the documentation for UIWindow. Is that what you were unsure about Jake?
Also, strangely, the UIWindow inherits the UIView. My view was inheriting from UIView so I changed it to UIWindow, since it's up the hierarchy. It compiles fine but I'm not messing with it anymore tonight. I'll see if I can figure out how to get a keyboard up tomorrow. Thanks everyone for your inputs.
bmantzey Wrote:The stacking of levels takes precedence over the stacking of windows within each level. That is, even the bottom window in a level obscures the top window of the next level down. Levels are listed in order from lowest to highest.
- Found this in the documentation for UIWindow. Is that what you were unsure about Jake?
Thanks but no, I was just making a strange observation that the keyboard *appears* to me to get to play outside the rules even though it belongs to UIWindow. My observation has zero bearing on reality, and did not directly refer to the question at hand, "What view does it belong to?", so I should have left it out. Sorry about the confusion.
How would I begin setting up the UITextField if I'm not loading from xib/nib?
Something like this (I added some extra settings):
Code:
myTextField = [[UITextField alloc] initWithFrame:MyCGRect];
[myTextField setDelegate:self];
[myTextField setBorderStyle:UITextBorderStyleRoundedRect];
[myTextField setBackgroundColor:[UIColor whiteColor]];
[myTextField setTextColor:[UIColor blackColor]];
[myTextField setClearButtonMode:UITextFieldViewModeAlways];
[myTextField setFont:[UIFont fontWithName:@"Arial" size:18.0f]];
[myTextField setPlaceholder:@"Tap here to edit"];
[myTextField setTextAlignment:UITextAlignmentCenter];
[myTextField setReturnKeyType:UIReturnKeyDone];
[myView addSubview:myTextField];
In this case, what is self?
Whatever you want it to be, but it has to conform to the <UITextFieldDelegate> protocol. It can be myView, or whatever. I have a global game instance that I often use as a catch-all delegate for all kinds of things like this because most of my games on iPhone are C. So like I said, the delegate could be anything.
[adding] as mentioned above, check out CrashLanding to see it in action
[adding] as mentioned above, check out CrashLanding to see it in action
Here are some delegate method implementations to look at:
Code:
- (void)textFieldDidEndEditing:(UITextField*)textField
{
NSLog([textField text]);
[textField endEditing:YES];
[textField removeFromSuperview];
}
- (BOOL)textFieldShouldReturn:(UITextField*)texField
{
// end editing
[texField resignFirstResponder];
return YES;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
// limit to 14 characters for fun
if ([[textField text] length] < 14 || [string length] == 0)
return YES;
else
return NO;
}AnotherJake Wrote:Here are some delegate method implementations to look at:
Code:
- (void)textFieldDidEndEditing:(UITextField*)textField
{
NSLog([textField text]);
[textField endEditing:YES];
[textField removeFromSuperview];
}
- (BOOL)textFieldShouldReturn:(UITextField*)texField
{
// end editing
[texField resignFirstResponder];
return YES;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
// limit to 14 characters for fun
if ([[textField text] length] < 14 || [string length] == 0)
return YES;
else
return NO;
}
Hi AnotherJake, could you explain me more or less what I should do to use keyboard in a OpenGL and C++ game (based on glpaint demo)? Is that possible? I would not like an edit field, just the keyborad in lanscape mode.
Thanks a lot for your help.

