5
votes

I want to make a custom keyboard perform like the iOS software keyboard with regards to accessibility. When a button-press adds a letter to a UITextField, the letter should be spoken by VoiceOver in the ‘added character tone‘. When a button-press deletes a letter from a UITextField, the letter should be spoken by VoiceOver in the ‘deleted character tone’.

Here is what I attempted:

  1. Created a UITextField in the view controller, in the storyboard.
  2. Created two UIButtons labeled ‘Type’ and ‘Backspace’ in the view controller, in the storyboard.
  3. Set the accessibility traits for both UIButtons to Keyboard Key.
  4. Hooked the storyboard UITextField up to an IBOutlet UITextField instance, textField.
  5. Hooked the storyboard ‘Type’ UIButton up to an IBAction, -type.
  6. Hooked the storyboard ‘Backspace’ UIButton up to an IBAction, -backspace.
  7. Implemented -type as: [[self textField] insertText:@"a"];.
  8. Implemented -backspace as: [[self textField] deleteBackward];.
  9. Made textField the first responder.

I also tried the same thing, moving the buttons into a UIView that was set as textField’s inputView.

The characters are properly added to and removed from the text field, but they are not spoken by VoiceOver. How can I make this work?

EDIT:
The hardware keyboard speaks correctly. It is only the custom software keyboard that is not speaking as it should.

2
When you do all this does your delegate get callbacks to textField:shouldChangeCharactersInRange:replacementString: when these keys are pressed?David Rönnqvist
No, it does not. However, asking the delegate if the text should change before calling -insertText: does not seem to make a difference.Endersstocker

2 Answers

0
votes

Voice Over may need to be enabled for the whole device for this to work. You can change this in accessibility. I'm not ure what to do if voice over is already enabled on the device.

0
votes

I noticed that to get “Spoken Content” » “Speak Screen” to speak the keyboard keys, too, I had to add the .keyboardKey to the button accessibilityTraits, e.g. in Swift:

button.accessibilityTraits = [.keyboardKey]

Or in Objective-C:

[button setAccessibilityTraits:UIAccessibilityTraitKeyboardKey];

And, obviously, if your buttons are images, you’ll want to add explicit accessibilityLabel for them, too.