I have a couple of iOS applications which present inherently linearly organised information, allowing the user to move forward and backward through the data with on-screen controls. I would like to allow users with the keyboard dock or a paired bluetooth keyboard to use the arrow keys to move back and forth as well. Since the apps are full-screen it is very important to the user experience that there is no risk of displaying an on-screen keyboard as a side-effect.
I cannot find an API that will let me do this in Apple's documentation; but I cannot be sure that I have used the right search terms.
What APIs are there which will allow me to achieve this?
Update: I have raised this as an enhancement on Apple's bug reporting site.
The answer in How can I respond to external keyboard arrow keys? - create a hidden text field and react to selection changes - worked for me.
You can easily determine which arrow keys are pressed by referring to UIKeyInput
and UIKeyInputDelegate
. The method you're looking for specifically is positionFromPosition:inDirection:offset:
.
After that method is called (it is used by iOS to determine the selection range) it will then call setSelectedText:
. Put NSLog
statements in the positionFromPosition:inDirection:offset:
to determine how it works (you're responsible for the plumbing).
Also look at the SimpleTextInput. This will provide you with a template on subclassing UITextInput
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With