Shashank Kaushik
Shashank Kaushik

Reputation: 177

ios VoiceOver focus not moving beyond navigation bar

VoiceOver focus not moving beyond navigation items. I am swiping right but focus trapped on the last element of navigation item. Probably it should move to the first element of the ViewController view. I have set accessibilityElements and made each element isAccessibilityElement = true. If I try to tap on any element of the ViewController view the focus trapped to status bar.

Upvotes: 6

Views: 3493

Answers (2)

Helam
Helam

Reputation: 1505

I recently encountered this issue at work in several instances and discovered a two-part root cause.

It is important to note that the root cause of our issues existed on the PREVIOUS view controller in the navigation stack, and not on the view controller where the issue manifested.

For example if the navigation stack looks like this where each letter is a view controller:

A -> B -> C

We were getting stuck in the navigation bar on view controller C due to issues in the code inside of view controller B.

The following is what solved it for us:

  1. Avoid setting accessibilityElements directly on the view controller. Manually setting accessibilityElements on the view controller itself can lead to various VoiceOver defects, such as getting stuck in different places or being unable to swipe to the keyboard. I recommend setting accessibilityElements on the view of the view controller instead, or even better if you can avoid setting accessibilityElements entirely and rely on the standard behavior.
override func viewDidLoad() {
    super.viewDidLoad()
    // Ideally, don't set `accessibilityElements` at all.

    // If necessary, set it on the `view` of the view controller.
    view.accessibilityElements = [oneOfYourViews, anotherOfYourViews]
    // ^

    // Don't set it on the view controller itself.
    accessibilityElements = [someView, anotherView] // Avoid doing this.
}
  1. Don't manually include the navigation bar in the accessibilityElements. The previous view controller in the navigation stack was including the navigation bar in it's accessibilityElements like this:
// Don't include the navigation bar in `accessibilityElements`
accessibilityElements = [navigationController?.navigationBar, otherView, moreViews]

This is unnecessary, as UINavigationController's default behavior should handle including the navigation bar. You should only need to set accessibilityElements on the views of your view controllers if you need to customize the order of the elements.

Upvotes: 2

D. Pratt
D. Pratt

Reputation: 464

I have noticed that sometimes testing VO has some funky issues like this when testing while logging (you are running on your device through Xcode). If you run it by launching the icon, rather than running it in Xcode, it may work normally.

If not, you can force focus on the first item outside your navigation by posting a UIAccessibility notification in a method like viewWillAppear:

UIAccessibility.post(notification: UIAccessibility.Notification.screenChanged, argument: whateverelementyouwantfocused)

Upvotes: 3

Related Questions