简体   繁体   中英

How can I change the order of accessibility elements in a view controller without losing access to the navigation bar?

I've got a view controller that contains a table view along with a few "floating" controls that appear visually at the bottom of the screen.

When navigating with VoiceOver, it would make more sense for the user to navigate like:

  • back button (navigation bar)
  • title (navigation bar)
  • edit button (navigation bar)
  • floating button
  • table contents

But currently, the navigation order is

  • back button (navigation bar)
  • title (navigation bar)
  • edit button (navigation bar)
  • table contents
  • floating button

When I explicitly set the accessibility elements for my view controller's view to change the order like

- (void)viewDidLoad {
  self.accessibilityElements = @[self.floatingButton, self.tableView];
}

the navigation order becomes

  • floating button
  • table contents

and the navigation bar is no longer accessible.

If I include self.navigationController.navigationBar at the beginning of the accessibilityElements array, then I get the navigation order

  • back button (navigation bar)
  • title (navigation bar)
  • edit button (navigation bar)

and swiping right again navigates back to the back button, so I can't reach the floating button or table contents.

Is there a way to reorder the accessible subviews without also losing access to the navigation bar?

I tried and reproduce the problem you mentioned in a blank project following this storyboard : 在此处输入图片说明 I read this a11y recommendations site to provide this code snippet I implemented to make it work as desired :

class TestButtonTableViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

    @IBOutlet weak var myTableView: UITableView!
    @IBOutlet weak var bottomButton: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()
        myTableView.delegate = self as UITableViewDelegate
        myTableView.dataSource = self as UITableViewDataSource
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        self.accessibilityElements = [bottomButton, myTableView]
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    func tableView(_ tableView: UITableView,
                   numberOfRowsInSection section: Int) -> Int {
        return 2
    }

    func tableView(_ tableView: UITableView,
                   cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        return zeCell = tableView.dequeueReusableCell(withIdentifier: "myPersoCell",
                                               for: indexPath)
    }
}

I made right flicks to get the next elements and obtained the illustrations hereunder : 在此处输入图片说明 在此处输入图片说明 The VoiceOver navigation follows the desired pattern :

  1. Back button (navigation bar) .
  2. Title (navigation bar) .
  3. Edit button (navigation bar) .
  4. Floating button.
  5. Table contents.

I specified nothing in particular and changed the order of accessibility elements in a view controller without losing access to the navigation bar .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM