我已经创建了UITableViewCell,它包含两个对象:
通常,当语音焦点UITableViewCell读取所有添加的标签时,没有任何问题,但在我的示例中,语音只读取标题,而不是webview html内容,用户必须向右和左滑动才能移动到下一个/前一个元素来读取webview的内容。
我的要求是,当声音聚焦于UITableViewCell时,语音应该一次读取UILabels和webview内容,因为作为开发人员,我们知道它是一个HTML,但是对于应用程序用户(盲人)则不知道。
另外,我还想知道如何禁用UIWebview可访问性。我尝试将isAccessibility设置为“否”,但仍然通过“声音而不是焦点”( Voice )。[self.webview setIsAccessibilityElement:NO];
如何解决这个问题?
发布于 2014-02-05 22:27:16
我通过在表格单元格视图中实现"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;
}
发布于 2014-02-05 14:17:19
不如:
[self.webview setAccessibilityElementHidden:YES]
然后使用accessibilityLabel属性在单元格上设置任何您喜欢的可访问性标签。
https://stackoverflow.com/questions/21571996
复制