Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIAccessibility change UITableView voiceover announcements (row # of #)

With VoiceOver enabled a user can use a 3 finger swipe gesture to scroll TableViews. VoiceOver verbally announces to the user a phrase indicating their location on the tableview i.e. the rows that are visible such as "Rows 1 to 4 of 5".

I would like to override this verbal prompt and get voiceover to announce something else to the user.

like image 553
Des Avatar asked Mar 18 '13 15:03

Des


2 Answers

Use UIScrollViewAccessibilityDelegate and implement the method -accessibilityScrollStatusForScrollView:

Example

- (NSString *)accessibilityScrollStatusForScrollView:(UIScrollView *)scrollView
{
    return @"Your text";
}
like image 138
Eporediese Avatar answered Sep 17 '22 16:09

Eporediese


You can't change only the message. You will have to override accessibilityScroll: and do the scrolling and then post the scroll announcement (at least I don't know any other way). It isn't super hard though.

What to do

Since you have a table view you can scroll to a certain row using scrollToRowAtIndexPath:atScrollPosition:animated:. You could decide that one accessibility element is X number of rows. In that case you get the set of visible rows from the table view and add or remove X to the row of the last or first cell (depending on if the scroll is up or down).

Finally to announce the that the table view did scroll you should post a "page scrolled" notification and pass the text to be read. Finally you should return YES to say that you handled the scrolling (if you don't then the event will continue to propagate).

Example implementation

A basic implementation could look something like this (I'm making some assumptions that may change depending on your code, like that there is only one section):

- (BOOL)accessibilityScroll:(UIAccessibilityScrollDirection)direction 
{
    BOOL isScrollingUp = NO;
    switch (direction) {
        case UIAccessibilityScrollDirectionUp: {
            isScrollingUp = YES;
        } break;

        case UIAccessibilityScrollDirectionDown: {
            isScrollingUp = NO;
        } break;

        default:
            // These cases are not handled
            return NO;
    }

    NSInteger numberOfCellsToScroll = 5; // Any number you'd like

    NSInteger newRow = -1;
    if (isScrollingUp) {
        newRow = [self.tableView indexPathsForVisibleRows][0].row - numberOfCellsToScroll;
    } else {
        newRow = [[self.tableView indexPathsForVisibleRows] lastObject].row + numberOfCellsToScroll;
    }

    [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:newRow inSection:0] 
                          atScrollPosition:UITableViewScrollPositionMiddle 
                                  animated:YES];

    UIAccessibilityPostNotification(UIAccessibilityPageScrolledNotification,
                                    @"YOUR CUSTOM TEXT FOR THE SCROLL HERE");

    return YES; // We handled the scroll
}
like image 33
David Rönnqvist Avatar answered Sep 17 '22 16:09

David Rönnqvist