I have UIView, on which I have few UI accessibility elements (all have attribute isAccessibilityElement = true
) and focus order is as below:
- back button (image)
- label
- label
- label
- label with accessibilityTraits = .button
Upon clicking on element #5 (label), I transition to the new ViewController using below code:
let storyboard = UIStoryboard(name: "Sheet", bundle: nil)
guard let viewController = storyboard.instantiateViewController(withIdentifier: "Sheet") as? SheetViewController else {
return
}
On the Sheet ViewController I have some buttons which perform different actions ie. copy text to the Clipboard. Once action is tapped I run function to dismiss Sheet View Controller and within competition handler I call mainVC.setAccessibilityFocus() function which forces accessibility focus on element #5 of my UIView.
self.dismiss(animated: true, completion: {
//some more code here
mainVC.setAccessibilityFocus()
})
Function within UIVIew:
func setAccessibilityFocus() {
UIAccessibility.post(notification: UIAccessibility.Notification.screenChanged, argument: my5thElement)
}
Expected behaviour is for the accessibility focus to go onto my 5th element (label) on the UIView. However no matter what I try, focus always goes onto first accessibility element of the UIView which is back button (#1 element).
Can anyone please advice what is the best practise in terms of the accessibility focus order in this scenario and how to force focus on the different element rather than the first one?