开发者

iPad "dismiss keyboard" button (lower right), how do I detect when this occurs? What function tells me it was pressed?

I have an ipad app that when you are in landscape view, the view will move up when the keyboard is brought in. When you press done on the keyboard, textFieldShouldRetu开发者_如何学编程rn and textFieldShouldEndEditing are called in which case, I move the view down in shouldEndEditing.

If the user presses the dismiss keyboard button, the keyboard does poof, yet the view is still stuck floating where I moved it.

I need to know how or what function is called when that button is pressed so I can redirect the function to textFieldShouldEndEditing.

Thanks!


You can listen for keyboard hide UIKeyboardWillHideNotification notification.

Example code is here http://developer.apple.com/iphone/library/samplecode/KeyboardAccessory/Listings/Classes_ViewController_m.html


When the "lower keyboard" button is pressed, the textfield delegate method of:

-(BOOL)textFieldShouldReturn:(UITextField *)textField

Won't be called.

When either the "lower keyboard" or "return button" are pressed, the:

-(void)textFieldDidEndEditing:(UITextField *)textField

Will be called.

I use a variable NSString *lowerKeyboardButtonPressed initially set to @"" which I set to @"N" in the textfieldShouldReturn method ... then in the textFieldDidEndEditing method I check to see if it is set to @"N" ... then I know if the return key or lower keyboard key was pressed. The last line in my textFieldDidEndEditing method sets the variable back to @"".


If you press the keyboard dismiss button and you have a hardware keyboard attached, then the willHide will only be called if you don't have an input accessory view. At which point you need to adjust in the willShow as well (which will have a negative difference between the UIKeyboardFrameBeginUserInfoKey and UIKeyboardFrameEndUserInfoKey keys).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜