【问题标题】:Voice over only reads UILabels and not UIWebview content旁白仅读取 UILabels 而不是 UIWebview 内容
【发布时间】:2014-02-05 08:23:37
【问题描述】:

我创建了 UITableViewCell,它包含 2 个对象:

  1. UILabel - 用于显示标题文本。
  2. UIWebView- 用于显示 HTML。

通常当语音聚焦 UITableViewCell 时,它会毫无问题地读取所有添加的标签,但在我的情况下,语音只读取标题而不是 webview html 内容,用户必须左右滑动才能移动到下一个/上一个元素阅读 webview 的内容。

我的要求是,当语音聚焦 UITableViewCell 时,语音应该一次性读取 UILabel 和 webview 内容,因为作为开发人员,我们知道它是 HTML,但对于应用程序用户(盲人) 没有任何想法。

我还想知道如何禁用 UIWebview 可访问性。我尝试将 isAccessibility 设置为 NO,但仍然 Voice Over 关注 UIWebview。 [self.webview setIsAccessibilityElement:NO];

如何解决这个问题?

【问题讨论】:

  • 兄弟,你是如何在 UIWebView 上集成语音的?

标签: ios accessibility voiceover


【解决方案1】:

我已经通过在表格单元格视图中实现方法“accessibilityLabel”解决了这个问题。对于 webview 获取 web 视图内容,将 html 转换为纯文本并使用它。不要忘记禁用标签和 webview 可访问性。

-(NSString*)accessibilityLabel{

NSString *labelText=nil;
NSMutableString *cellLabelText=[[NSMutableString alloc] init];

//Set label
[cellLabelText appendString:[NSString stringWithFormat:@", %@", self.titleLabel.text]];

//Fetch web view content, convert html into plain text and use it.
NSString *html = [self stringByEvaluatingJavaScriptFromString: @"document.body.innerHTML"];
NSString *plainText=[self convertHTMLIntoPlainText:html];

[cellLabelText appendString:plainText];


labelText=[NSString stringWithString:cellLabelText];
[cellLabelText release];


return labelText;
}


-(NSString *)convertHTMLIntoPlainText:(NSString *)html{

NSScanner *myScanner;
NSString *text = nil;
myScanner = [NSScanner scannerWithString:html];

while ([myScanner isAtEnd] == NO) {

    [myScanner scanUpToString:@"<" intoString:NULL] ;

    [myScanner scanUpToString:@">" intoString:&text] ;

    html = [html stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@>", text] withString:@""];
}
//
html = [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

return html;
}

【讨论】:

    【解决方案2】:

    怎么样:

    [self.webview setAccessibilityElementHidden:YES]
    

    然后使用accessibilityLabel 属性在单元格上设置您喜欢的任何可访问性标签。

    【讨论】:

    • 感谢回复,但我想禁用 UITableViewCell 内部的 webview 的可访问性,VO 应该一次性读取单元格标签和 webview 内容,而不需要额外的努力,否则对任何人来说都更加困难盲人导航和阅读屏幕内容。
    • 不错。很高兴您找到了解决方案。
    猜你喜欢
    • 2010-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多