I'd like to call a method every time a different element is focused while VoiceOver is active. I was hoping there would be some UIAccessibilityNotification
for this, but I can't seem to find any.
Ultimately, my goal is to add an additional condition prior to reading the accessibility label. For example, as opposed to saying (by default) "If UIButton
becomes focused: read label", I'd like to be able to say "When UIButton
becomes focused AND UIButton
's background color is blue: read label".
So my question is: how do I either add an additional condition prior to reading the label, or receive a notification when a new element becomes focused?
You can use the UIAccessibilityFocus
protocol to detect changes in focus by accessibility clients (including VoiceOver). Note that UIAccessibilityFocus
is an informal protocol that each accessibility element must implement independently.
That said, for your use case, Aaron is right to suggest returning a different accessibilityLabel
under each condition.