12

Working with Accessibility

While VoiceOver reads the elements in the application in an order,Is there anyway to shift the focus between the elements? I tried working with "nextResponder",but it is not working.

Cwala
  • 29
  • 1
  • 2
  • 12
  • 1
    **Bounty!! YEAH!!!** I would like to know (if possible) how can I tell voiceover to *jump* from the last UIToolBarButton in the UIToolbar to the first object in the main view, so the user can *loop* through all the controls in the screen infinitely ... Possible? – nacho4d Apr 19 '12 at 11:27
  • **Edit:** The last button in the UIToolbar is the last control in the whole screen so pressing VO+rightArrow does nothing (usually pressing VO+arrowRight will *jump* to the next control but since this is the last one it stops). In this scenario I would like to tell VoiceOver to *jump* to the first object so the user can loop infinitely through all the controls in the scree. I hope is better explained now :) – nacho4d Apr 19 '12 at 14:39

5 Answers5

4

As of iOS 6, you can set the focus to a specific element with a UIAccessibilityLayoutChangedNotification, passing the element

UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, firstBottom);

but if you're trying to completely change the “tab order” I don’t know of a way to do it.

David Dunham
  • 8,139
  • 3
  • 28
  • 41
  • As far as I can see `UIAccessibilityLayoutChangedNotification` is available from iOS 3. What changed in iOS 6? – David Rönnqvist Apr 04 '13 at 06:54
  • There was no documentation that suggested you could pass any specific value, prior to iOS 6. And, I’m pretty sure passing a value didn’t do anything useful. – David Dunham Apr 04 '13 at 13:52
  • Oh, the current documentation doesn't reflect that. – David Rönnqvist Apr 04 '13 at 14:00
  • If you look at the older documentation, it says “This notification does not include a parameter.” I was told that it is ignored prior to iOS 6. – David Dunham Apr 04 '13 at 14:23
  • A layout changed notification should be posted, as the name indicates, when the layout changes. It should not be used to simply move focus to a element. – Kasper Munck May 01 '15 at 09:00
  • I don’t think there is any other way to focus on an element. In general, you use this when the screen *has* changed, and you want the focus to start on a particular element. – David Dunham May 01 '15 at 13:26
  • 1
    Use self.accessbilityElements = @[item1, item2..]; http://stackoverflow.com/questions/7529464/ios-change-accessibility-focus – Rushabh Jan 18 '17 at 22:25
0

This is a shot in the dark, but have you tried changing the accessibilityLabel or accessibilityHint in accordance when you want the order to change? If you can trick the VoiceOver to believe the text has changed, I would expect that it would change focus to it appropriately.

The timing would be the hard part, since it doesn't appear there are any delegate callbacks for when VoiceOver is crawling your view, so you may have to estimate the time to pass before trying to update the accessibility hint/value.

My last thought would be to mark the UIView that you want to bring attention to with the UIAccessibilityTraitUpdatesFrequently accessibility trait. That might be the closest you can get without tapping into hidden Apple libraries.

Sean Freitag
  • 930
  • 1
  • 6
  • 15
0

Check out this post for how to handle special ordering of elements for voice over. I just used this approach in the app I'm working on.

Community
  • 1
  • 1
DrDisc
  • 281
  • 4
  • 12
0

I tried UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, elementName); to change the focus on a different element. The behavior was that the focus got shifted to new element, but Voice Over would first announce the page title and then the accessible label value of the new element.

Kunal Shah
  • 51
  • 4
0

Customise Accessibility for a View:

You can customise the order(in which voice over should traverse the screen elements) by overriding accessibilityElements property of parent view in below manner.

self.accessibilityElements = [childView1, childView2, childView3]

With that voice over will follow the sequence like childView1 -> childView2 -> childView3.

Changing Accessibility focus to other element programatically:

At any time you can shift the focus to another element by using below code.

UIAccessibility.post(notification: .layoutChanged, argument: childView2)

With above code, voice over focus would be shifted to childView2 and then will follow the same sequence defined by accessibilityElements i.e. childView2 -> childView3 -> childView1... and so on

Customising Accessibility Order for Complex Views:

You can customise it further and If a view has multiple child views with further grand children views, then you can achieve accessibility order by defining accessibilityElements of main parent view by using accessibilityElements of all child views.

For example, for below view hierarchy, we have
View Controller Example

To define custom order of accessibility elements for such views, we can define in below manner.

var customElements = childView1.accessibilityElements
customElements.append(contentsOf: childView2.accessibilityElements)
customElements.append(contentsOf: childView3.accessibilityElements)

parentView.accessibilityElements = customElements
Om Prakash
  • 51
  • 4