user2603138
user2603138

Reputation: 1587

iOS - Accessibility methods - moving focus

I am working on an app and trying to make it as accessible as possible. I am trying to move focus to a certain element once an action takes place. I was curious about the difference between these two functions:

UIAccessibilityFocusedElement vs. UIAccessibilityPostNotification

If someone could explain the difference between the two it would be greatly appreciated.

Upvotes: 2

Views: 9051

Answers (2)

Adam Tucholski
Adam Tucholski

Reputation: 1077

UIAccessibilityPostNotification is used to change things (like focused elements but also pausing and resuming assistive technology like that:

UIAccessibility.post(notification: .pauseAssistiveTechnology, argument: UIAccessibility.AssistiveTechnologyIdentifier.notificationSwitchControl)
UIAccessibility.post(notification: .resumeAssistiveTechnology, argument: UIAccessibility.AssistiveTechnologyIdentifier.notificationSwitchControl)

It can also announce something:

UIAccessibility.post(notification: .announcement, argument: "Say something")

or refresh focus after accessibility scroll

UIAccessibility.post(notification: .pageScrolled, argument: nil)

On the other hand UIAccessibilityFocusedElement can't change anything. It just returns currently focused element (or nil) this way:

UIAccessibility.focusedElement(using: UIAccessibility.AssistiveTechnologyIdentifier.notificationVoiceOver)

On a side note - for now only assistive technology that can be paused or resumed is notificationSwitchControl, trying that with Voice Over causes crashes

Upvotes: 4

dashuser
dashuser

Reputation: 181

If you are trying to move focus to an element based off an actions / screen change scenario.

I think you should probably take a look at:

UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, element_to_be_focused>);

Should be posted when a new view appears that encompasses a major portion of the screen.

or

UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, element_to_be_focused); 

Should be posted when the layout of a screen changes, for example when an individual element appears or disappears.

Upvotes: 2

Related Questions