问题描述
启用VoiceOver后,用户可以使用3指轻扫手势滚动TableView。
VoiceOver向用户口头宣布一个短语,表明他们在桌面视图上的位置,即可见的行,例如第1行到第4行。
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.
推荐答案
你无法改变仅消息。您将必须覆盖 accessibilityScroll:
并进行滚动,然后发布滚动公告(至少我不知道其他任何方式)。但这并不是很难。
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.
因为你有一个表格视图你可以滚动使用 scrollToRowAtIndexPath:atScrollPosition:animated:
到某一行。您可以确定一个辅助功能元素是X行数。在这种情况下,您从表视图中获取可见行的集合,并将X添加或删除到最后一个或第一个单元格的行(取决于滚动是向上还是向下)。
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).
最后,为了宣布表视图滚动,您应该发布页面滚动通知并传递要读取的文本。最后你应该返回 YES
来表示你已经处理了滚动(如果没有,那么事件将继续传播)。
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).
基本实现看起来像这样(我做了一些可能会改变的假设取决于您的代码,例如只有一个部分):
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
}
这篇关于UIAccessibility更改UITableView画外音公告(#行#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!