开发者

Detecting iPad keyboard hide versus external keyboard connect?

开发者 https://www.devze.com 2022-12-30 20:37 出处:网络
The iPad virtual keyboard will disappear in one o开发者_如何学编程f (at least) these 3 circumstances:

The iPad virtual keyboard will disappear in one o开发者_如何学编程f (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.


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


It sounds like you're just trying to figure out when a user is done editing. You could listen for the UITextFieldTextDidEndEditingNotification notification for cases 1 and 2.

A much simpler solution would be couldn't you just check against the editing property of UITextField to determine if it's still supposed to be editing or not? I don't have a physical keyboard, so I have no way to test this. I'm just guessing.

Here's a link to the documentation on that property: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITextField_Class/Reference/UITextField.html#//apple_ref/occ/instp/UITextField/editing

I'm very curious to know if this works or not... :)

0

精彩评论

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