ios - Voice over 只读取 UILabels 而不是 UIWebview 内容

标签 ios accessibility voiceover

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

  1. UILabel - 用于显示标题文本。
  2. 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/

相关文章:

html - A11y 用于空 anchor 标签

swift - 可访问性自定义操作未在 Swift 中公布

javascript - 在 UIWebView 中删除网站标题后的差距

ios - 知道两个CGRect的交点

android - 如何编程图形界面是盲的?

html - 是否有标准方法为 HTML5 广告/动画的屏幕阅读器提供 alt =""文本?

ios - Alamofire 请求未在 swift 5 中执行

ios - 无法完全关闭我以前的 alertcontroller

ios - 自定义 UILongPressGestureRecognizer 的问题不适用于 VoiceOver

ios - 应用程序读出文本?