Reputation: 591
When my user presses a button with invalid text i show a UILabel (previously hidden) containing text "Invalid values entered".
I would like voice over to automatically read out this label as it appears. How do i do this?
Upvotes: 4
Views: 9151
Reputation: 4689
UIAccessibility.post(notification: .announcement, argument: "your text")
There does not seem to be a queue (still, on iOS 13). If you post your announcement immediately after a user action, such as a button tap, it may get swallowed by the button's automatic voice-over announcement. In this case you should post your announcement after a suitable delay (as mentioned here). If that delay is too short, your announcement might cut into the button's announcement.
AVSpeechUtterance
will speak the text to all users, UIAccessibility.post
only to those that have selected Voice-Over in their accessibility settings, f.i. because they are visually impaired.
Upvotes: 3
Reputation: 56635
If you want to present some important information to a Voice Over, then you should post an "accessibility announcement":
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, // announce
@"My important information"); // actual text
Upvotes: 12
Reputation: 504
You want to do something like this:
AVSpeechSynthesizer* speechSynth;
AVSpeechUtterance *utterance;
speechSynth = [[AVSpeechSynthesizer alloc] init];
speechSynth.delegate = self;
utterance = [AVSpeechUtterance speechUtteranceWithString:@"Hello, world!"];
[speechSynth speakUtterance:utterance];
Note: This is iOS7 only
Upvotes: -1