Is there any way to have VoiceOver read a label on

2019-04-08 03:38发布

问题:

I'd like to have my QR code scanning app inform the user when it finds a QR code. For sighted users, this works using a label at the bottom that updates to notify the user. However, a blind user would have to tap on that label again to have it read by Voice Over. I would much prefer it to just read automatically.

The closest I can find to this question is UIAccessibility - Read all the labels and buttons on the screen from top to down, which wasn't possible. While this doesn't bode well for my app, that was a year ago. Has Apple updated it's UIAccessibility protocol in any way to allow this?

As a last resort I suppose I could play my own mp3 recording if VoiceOver is on.

Any help is greatly appreciated!

回答1:

You can make VoiceOver speak any string any time you want by calling:

UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, NSLocalizedString("QR code has been detected", comment: ""))

Swift 4

UIAccessibility.post(notification: .announcement, argument: "Text")

There is no direct way to tell VoiceOver to speak updates of an element that VoiceOver cursor is not on. This (i.e. speaking the same content "manually") is a feasible workaround.



回答2:

You can move VoiceOver focus to an element by using the following:

UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, elementToFocusOn)

VoiceOver will then parse and read the accessibility properties associated with that element.