Question

I am currently having trouble setting the focus of VoiceOver a specific label. According to Apple 's developer site (https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/Accessibility/AccessibilityfromtheViewControllersPerspective.html), the focus of the first object can be changed by adding the following code snippet:

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

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

Unfortunately, I was unable to get this to work properly in iOS7.

Edit - To clarify, what I meant by not working properly was that it default to the top left most bar button in the navigation bar. I can verify that the label that I am trying to get focus on is not nil, and is a subview of another view that I have in place of the navbar title.

Was it helpful?

Solution

Your code is indeed correct. I have found it sometimes doesn't focus the element you've specified because of some conflict with the default focus behavior. To fix the issue and ensure the element you've specified is focused, just delay that call. It's somewhat fragile but that's the only solution I've found. You may want to play with the delay amount - the following is a 0.75 second delay.

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.75 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, self.myFirstElement);
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top