11

I'm having an issue with moving the voiceover cursor to a specific element on viewDidAppear. I followed Apple's guidelines for focusing on a specific element, in this case a dismiss button, but the cursor ends up elsewhere

Here is my Code:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification,
                                self.dismissButton);
}

Any help, ideas, would definitely be appreciated! thank you so much.

3254523
  • 3,016
  • 7
  • 29
  • 43

3 Answers3

10

If I remember correctly i was not able to reliably focus on elements on first of the view as VO will generally focus on the top of the view.

The code you are doing is correct, but at this point the system will trigger it's own event and override yours.

What you can try to do is post a notification with a delay. But that will result in focus jumping around a little bit when opening the view.

It's not much of an answer, but that is where I'm at at the moment. I'll update you if I figure out a way to do it.

Feras Arabiat
  • 826
  • 6
  • 11
  • Did you figure out a better way? Im also doing the same but it's little bit buggy. – Rakitha Nov 11 '14 at 09:00
  • Have not figured out a better way so far. It's been a while since I looked into Accessibility, I'll update the answer if I find a new way to do this. – Feras Arabiat Nov 11 '14 at 09:10
3

This answer may be of help.

Basically you need to wrap your elements in a container view if they're not in one already and then override the methods specified.

By giving your desired element a tag that is lower than the other elements you can have the view sort the array to ensure that it will be the first element in the accessibilityElements array used by VoiceOver. Or you can adapt the sort method to sort another way.

Community
  • 1
  • 1
josef
  • 867
  • 12
  • 28
  • The downside of this method is that the order of the elements actually changes as well. People can move from element to element by swiping left or right and this method of sorting by tag will mess up the order in an illogical way. What you really want is just have a natural chronological order but just let one element (not the first) receive focus when the view appears. I also had to settle for the delay as suggested by @feras-arabiat which is far from ideal. – Marco Miltenburg Oct 22 '15 at 07:49
3

FYI: As of iOS 11, both UIAccessibilityScreenChangedNotification and UIAccessibilityLayoutChangedNotification reliably focus Voice Over elements for me.

Rudolf Adamkovič
  • 31,030
  • 13
  • 103
  • 118
  • For what I needed, updating focus on an element in table cell, using `UIAccessibilityLayoutChangedNotification` in the data source allowed me to focus on the correct element in the cell when the cell was being reloaded by passing the correct element in as the argument to the notification, (can also accept a string). Perfect. – elmarko Feb 03 '20 at 13:27
  • This doesn't work in a native navigation controller setup with either using a native navigation bar or a custom UIView which acts as a navigation bar. The focus always ends up on the back button of either the native or custom nav. bar. However, it does speak out the next element which was set up in UIAccessibilityScreenChangedNotification – nr5 Nov 26 '20 at 07:39