Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting iPad keyboard hide versus external keyboard connect?

The iPad virtual keyboard will disappear in one of (at least) these 3 circumstances:

  1. If the control (say, a UITextField) programmatically resigns first responder.
  2. If the user taps the "dismiss keyboard" button in the lower right.
  3. If the user connects to the USB/keyboard dock peripheral.

In all cases, I get the UIKeyboardWillHideNotification.

The problem is that the first two cases are generally equivalent-- in other words, the user is done editing the text field. But in the third case, the text field is still being edited, just from another input source.

The problem is detecting the difference between cases 2 and 3. All I get in both cases is UIKeyboardWillHideNotification. In case 2, I generally want to also lock the edit control and commit the value. In case 3, I generally want to do nothing and allow editing to continue.

But how can I tell the difference?

Apple's Pages app seems to be able to distinguish this on document-title renaming.

like image 381
Ben Zotto Avatar asked May 20 '10 16:05

Ben Zotto


1 Answers

I would look at the UIKeyboardBoundsUserInfoKey passed with the notification. The physical keyboard probably has empty bounds.

like image 118
drawnonward Avatar answered Nov 15 '22 17:11

drawnonward