Handling Text Input with an iPhone's Virtual Keyboard
Does anyone know of a w开发者_开发技巧ay to utilize the iPhone's hardware keyboard with something other than a UITextView/Field, basically I want to be able to send characters pressed on the virtual keyboard to my own view. If anyone can help me out that'd be immensely appreciated!!
I've done this by using a hidden text field. Not incredibly elegant but it works, basically on whatever event you want to show the keyboard for you call
[myHiddenTextField becomeFirstResponder];
then monitor the input using the text field's text property, register for the event to let you know when something has been typed
[myHiddenTextField addTarget:self action:@selector(processKeyboardInput:) forControlEvents:UIControlEventEditingChanged];
You could place a hidden UITextField
off screen, and tell it to becomeFirstResponder
this will show the keyboard.
Then you can listen for the text did change notification that the text field posts and do what you need in there.
The notification is posted whenever a key is tapped, including the delete key.
精彩评论