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?

有帮助吗?

解决方案

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

其他提示

Swift 5

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.

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top