Kartik
Kartik

Reputation: 2609

How do I get UIButton to announce a double tap on voice over?

I am an IOS beginner trying to enable accessibility for UIButton. For legacy purposes, we are still using Objective-C to write IOS apps. My code for a button is as follows:

-(UIButton*) initializeDoneButton {
    UIButton *doneButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 25, 10)];
    [doneButton setTitle:@"Done" forState:UIControlStateNormal];  
    [doneButton addTarget:self action:@selector(finishTheProcess:) 
        forControlEvents:UIControlEventTouchUpInside];
    [doneButton setIsAccessibilityElement:YES];
    [doneButton setAccessibilityLabel:@"Done Button"];
    [doneButton setAccessibilityHint:@"Tap button to complete the process"];
    return doneButton;
}

My callback function

- (void) finishTheProcess:(UIButton *)sender {
    // Code here to finish the process.
}

I see the voice over announce just one tap, and not the double tap. Ideally, the first tap should announce the title of the label "Done" on voice over. The second tap should execute the action callback function. Is this even possible?

I have read Apple's tutorial on Accessibility, but I am unable to figure out how to enable accessibility for UIButton.

Update

This is the bug report that was filed against my name

Actual Result : Voice Over announces only tap instead of double tap for “Done”.

Expected Result : Voice Over should announce as double tap.

Upvotes: 2

Views: 5203

Answers (2)

Brian Li
Brian Li

Reputation: 3060

tl;dr - modify the accessibilityHint to say "double tap"

Accessibility elements on iOS have a number of Voice Over traits that can be announced. It is first important to understand the function of the accessibility focus. In order to differentiate between a user intending to tap a button on the screen versus wanting to learn more about the element, Apple implements an accessibility focus that is basically like hovering your mouse over a web page element on a browser to get more information. This focus is activated when the user taps a single time on an accessibility element or swipes left/right between elements.

Once the accessibility element has been tapped, Voice Over announces information that helps the user understand the element of the accessibility focus. These announcements can be customized through the accessibility functions and are stated in the following order.

  1. Accessibility Label - descriptor for the accessibility element

    doneButton.accessibilityLabel = "Done";

  2. Accessibility Trait - one of a few commonly defined traits (e.g. button, header)

    doneButton.accessibilityTraits = UIAccessibilityTraitButton;

*this trait will default to UIAccessibilityTraitButton for objects of class UIButton

  1. Accessibility Hint - explains the function of the accessibility element

    doneButton.accessibilityHint = "Double tap the button to complete the process.";

*many users of accessibility will know to double tap to press the button once the UIAccessibilityTrait is announced

There are additional accessibility traits that can be set, but these are the commonly used ones that will cover most of the functionality that you require. Your code is actually really close to being operational. All you really needed to do was modify the accessibilityHint to say what you wanted Voice Over to announce.

Upvotes: 4

Bharath
Bharath

Reputation: 125

Add doneButton.accessibilityTraits = UIAccessibilityTraitButton; inside of your initializeDoneButton method.

Upvotes: 1

Related Questions