7

I have a view controller with this layout (note that yellow and table views are siblings):

enter image description here

I want the yellow view to act as a container, so I'm doing this in viewDidLoad:

yellowView.isAccessibilityElement = true
view.accessibilityElements = [yellowView!, tableView!]

When in Voice Over, I select "Containers" from the accessibility rotor and expect to be able to swipe up and down to move from the yellow view to the table view and back again:

Yellow (swipe down) → TableView (swipe down) → Tabbar (swipe up) → tableView (swipe up) → Yellow

However, this is not the case - after the tableView gains focus, swiping up does not move focus to the yellow view, it just stops there. Swiping down, moves to the tabbar - it seems that my custom view is ignored as container.

I have experimented with many combinations of adding superviews and setting isAccessibilityElement = false to them, but nothing seems to work.

Does anybody know how to solve this?

XLE_22
  • 5,124
  • 3
  • 21
  • 72
phi
  • 10,634
  • 6
  • 53
  • 88

2 Answers2

5

Did you set an accessibilityLabel on the yellowView or try changing the accessibilityContainerType = .semantic?

I think VoiceOver is not finding yellowView because the rotor is looking for UIAccessibilityContainer but the default container type is .none for UIView. However, a UITableView has a default container type of .semantic.

Mary Martinez
  • 314
  • 5
  • 12
4

it seems that my custom view is ignored as container.

Apparently, only native elements may be recognized as containers for the rotor.
I tried by creating an UIAccessibilityElement inside a view defined as its container with an accessibilityContainerType but no results.

I never use the rotor with the container item but this issue has aroused my curiosity.
I looked into this problem and found out an interesting answer that highlights the same a11y trait value for all the native containers... those that are analyzed by VoiceOver as such at least.

Override the trait value of your specific containers as follows for instance:

override var accessibilityTraits: UIAccessibilityTraits {
    get { return UIAccessibilityTraits(rawValue: 0x200000000000) }
    set {  }
}

This is a workaround because nothing else seems to be done for custom containers but I'm not a big fan of using raw values that may change or may not be used in a future release.

Anyway, following this rationale, you can now setup accessibility containers so that gestures work properly with the VoiceOver rotor.

⚠️ ⬛️◼️▪️ EDIT ▪️◼️⬛️ ⚠️ (2023/04/02)

Thanks to Mary Martinez for the true answer⟹ using semanticGroup as a container value is definitely made for iOS.

In the 2020 WWDC video entitled Accessibility design for Mac Catalyst, it's highlighted in the "What are accessibility containers?" section.

No need anymore to use the terrible workaround I provided.

XLE_22
  • 5,124
  • 3
  • 21
  • 72