I'm facing an accessibility issue, where when I call UIViewController.addChild(_:)
and pass in another instance of a UIViewController, the VoiceOver focus is jumping to the "Back" button in the navigation bar. How might one go about avoid this behaviour and having the accessibility/voiceover focus remain where it was at the time of adding the child?
I was able to brute force the system into not doing this by calling
parent.navigationController?.navigationBar.accessibilityElementsHidden = true
parent.view.accessibilityElementsHidden = true
parent.addChild(self)
parent.view.addSubview(self.view)
self.didMove(toParent: parent)
Later on, once I've configured my view a little, and then presented the child view I reset all the values using the following:
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
parent.navigationController?.navigationBar.accessibilityElementsHidden = false
parent.view.accessibilityElementsHidden = false
UIAccessibility.post(notification: .layoutChanged, argument: SOME_UI_VIEW)
}