3

How do I set the UIAccessibility focus on the content of the selected tab of a UITabBarController? It's keeps focussing on the selected UITabBarItem.

I've tried to set the focus in the UITabBarControllerDelegate:

    func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {

        if let destination = (viewController as? UINavigationController)?.viewControllers.first {
            UIAccessibility.post(notification: .screenChanged, argument: destination)
        } else {
            UIAccessibility.post(notification: .screenChanged, argument: viewController)
        }
    } 

I've also tried to set the focus in the selected UIViewController:

    override func viewDidAppear(_ animated: Bool) {

        super.viewDidAppear(animated)

        UIAccessibility.post(notification: .screenChanged, argument: accessibilityElements?.first)
    }

The accessibility focus does not change unfortunately. I'm not sure if this is an iOS 13 issue or a general tabbar issue, as even Apples own AppStore app does not change accessibility focus when selecting a tab.

XLE_22
  • 5,124
  • 3
  • 21
  • 72
Rool Paap
  • 1,918
  • 4
  • 32
  • 39

1 Answers1

0

I'm not sure how much it helps but I've managed to find a workaround by posting the notification with a delay.

override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        if UIAccessibility.isVoiceOverRunning {
             DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(1.0 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: {
                 UIAccessibility.post(notification: .layoutChanged, argument: self.whateverElementYouNeed)
             })
        }
}
Aracet
  • 219
  • 2
  • 4
  • 2
    Why do you use such a complex method to add time to the async? Also this seems to work for .announcement, but not for .screenchanged. – Charlie S Jul 15 '21 at 16:09