Possible Duplicate:
How can I detect if an external keyboard is present on an iPad?
When a user begins editing a textfield in my iPhone app’s UI, I want to use the space between the textfield and the keyboard for a list of related options.
Using the regular (on-screen) keyboard from iOS, there are a couple of convenient notifications to listen to, that help me decide how much space I have left for the list in between.
However when you attach (or simulate the use of) a hardware keyboard, these notifications are not posted anymore. Not too unexpected, but this leaves me with a bit of a challenge. If the user uses the hardware keyboard, I have more space for the list.
But how can I determine whether the user has a hardware keyboard or not, if there’s no triggered notification or delegate method to listen to? Or is there?
What’s also to be considered is that a user can first use the app with the software keyboard and then attach his/her hardware keyboard and continue working with the app. At that point, the software keyboard will hide, but the user is still editing the textfield.
I found one old dupe for this question, but it is unanswered:
Input accessory views are shown at the bottom of the screen if there’s a hardware keyboard attached (otherwise they’re attached to the top of the on-screen keyboard).
Set the accessory view of your input view to an empty
UIViewof sizeCGRectZero. You will receive the show / hide notifications for both cases, and be able to determine the available screen size from the metrics in the notification’s userinfo dictionary.Logged metrics – note the frame in
UIKeyboardFrameEndUserInfoKeyis off screenUpdate – very similar to user721239’s answer in the related question.