我创建了 UITableViewCell,其中包含 2 个对象:
- UILabel - 用于显示标题文本。
- UIWebView - 用于显示 HTML。
通常,当语音聚焦 UITableViewCell 时,它会毫无问题地读取所有添加的标签,但在我的情况下,语音仅读取标题而不是 webview html 内容,用户必须向右和向左滑动才能移动到下一个/上一个元素读取webview的内容。
我的要求是,当语音聚焦 UITableViewCell 时,语音应该一次性读取 UILabels 和 webview 内容,因为作为开发人员我们知道它是 HTML,但对于应用程序用户(盲人) 对此没有任何想法。
我还想知道如何禁用 UIWebview 可访问性。我尝试将 isAccessibility 设置为 NO,但仍然 Voice Over 聚焦 UIWebview。
[self.webview setIsAccessibilityElement:NO];
如何解决这个问题?
最佳答案
我通过在表格单元格 View 中实现方法“accessibilityLabel”解决了这个问题。对于webview获取web View 内容,将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;
}
关于ios - Voice over 只读取 UILabels 而不是 UIWebview 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21571996/