I am designing an app with accessibility enabled. I have
a rightBarButtonItem
on the navigationBar
, several labels in between
and a button located at the bottom.
I want to achieve the following behaviour : Every time the current view is loaded, the VoiceOver focus will:
- start from the topmost label
- visit all labels from top to bottom
- then, the bottom button
- finally, rightBarButtonItem
To ensure such order, I coded in the viewController
navigationController?.view.accessibilityElements = [label1, label2, button, navigationItem.rightBarButtonItem]
It did ensure the read order but the focus order failed at the rightBarButtonItem. It couldn't be clicked.
How to solve this problem?
Every time your current view is loaded, use the UIAccessibilityPostNotification method to get your purpose.
There are several types of change notifications but UIAccessibilityScreenChangedNotification may be the one you're interested in.
It notifies that the whole page has changed including
nil
or aUIObject
as incoming parameters :nil
, the first accessible element in the page is focused.UIObject
, focus is shifted to the specified element.This notification comes along with a vocalization including a sound like announcing a new page.
EDIT
I misunderstood your problem that is pretty much complicated than I thought.
If you want to have an impact on the navigation bar items, you should make the native ones inaccessible and create your own custom elements to order and/or add custom actions for instance.
Let's take your example with a label, a button and a navigation bar including a right bar button (I don't take into account a potential back button).
Follow the steps hereunder in your view controller :
STEP 1 : create your outlets.
STEP 2 : hide your navigation bar items so as not to listen to their vocalization.
STEP 3 : create an accessible element for the right bar button.
The last step consists in adding a single action or more to your right bar button according to your application purpose.
Once done, you can customize with this approach and read/focus order to content view first then the navigation items as stated in your question.
This solution may be optimized but it allows to reach your goal.