0

I have UIView, on which I have few UI accessibility elements (all have attribute isAccessibilityElement = true) and focus order is as below:

  1. back button (image)
  2. label
  3. label
  4. label
  5. 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?

marika.daboja
  • 881
  • 13
  • 27
  • correct me if i am wrong. you are try to pass data between 2 view controller? –  May 07 '21 at 06:47
  • No, I'm not passing data between the View Controllers. I'm trying to force accessibility focus on a particular element (which is 5th in default order) from the first View after dismissing second View Controller. – marika.daboja May 07 '21 at 11:10
  • can you please pass (uiview) which contains 5th element in argument and let me know it working or not. –  May 07 '21 at 11:24
  • Im sorry - but can you be more specific or provide me with the sample (Im new to the iOS) – marika.daboja May 07 '21 at 11:48
  • check this : https://stackoverflow.com/questions/7509748/initial-voiceover-selection –  May 07 '21 at 11:52
  • hmmm.. Im already calling UIAccessibility notification and it does not help (it gets overwritten somehow I feel) by default iOS focus order – marika.daboja May 07 '21 at 13:46
  • Have you figured it out? I have a similar issue: the first element gets read out and then it moves immediately to my posted element. I don't want the first element to get read out as well. – zdtorok Feb 27 '23 at 13:56
  • @zdtorok That was long time ago but from my memory I did not get it fixed. However I managed to apply a workaround by delaying first element from displaying by small amount of time (not noticeable for the end user) and that way voice over was reading in order I needed it to be. – marika.daboja Feb 27 '23 at 22:09
  • I see, thanks for your feedback then I'll look further, hopefully there is a solution :) – zdtorok Mar 01 '23 at 09:13

0 Answers0