Initial VoiceOver selection

David Dunham picture David Dunham · Sep 22, 2011 · Viewed 6.9k times · Source

I'm adding VoiceOver support to my app. So far, so good, but I'd really like to be able to specify which element is the first one spoken after a UIAccessibilityScreenChangedNotification. I haven't seen a way to do this. Making something the summary element doesn't really seem to do it. Am I missing something?

Answer

Jeroen Leenarts picture Jeroen Leenarts · Dec 18, 2012

THis has always been perfectly possible to do.

Just write something along the lines of:

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

    UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification,
                                self.myFirstElement);
}
@end

This works for both the UIAccessibilityScreenChangedNotification and the UIAccessibilityLayoutChangedNotification. More info: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIAccessibility_Protocol/Introduction/Introduction.html#//apple_ref/c/data/UIAccessibilityLayoutChangedNotification And here: http://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/Accessibility/AccessibilityfromtheViewControllersPerspective.html#//apple_ref/doc/uid/TP40007457-CH2-SW1

Now for Swift 5
override func viewDidAppear(_ animated: Bool) {
    UIAccessibility.post(notification: UIAccessibility.Notification.screenChanged,
                         argument: myFirstElement)
}