如何为 tableview 上的 webview 内容启用 VoiceOver [英] How can I enable VoiceOver for webview content on tableview

查看:31
本文介绍了如何为 tableview 上的 webview 内容启用 VoiceOver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常情况下,VoiceOver 可以正确读取使用 WKWebView 加载的网页内容,并且可以读取按钮和链接.

然而,当我在UITableViewCell上添加WKWebView并在UITableVIew中显示时,VoiceOver无法识别它.

根据apple的tableview文档,为了使UITableViewCell上的每个内容分别被VoiceOver识别,需要将单元格的isAccessibilityElement设置为false,并将视图的isAccessibilityElement设置为true.

但是如果WKWebViewisAccesibilityElement设置为true,则视图本身是聚焦的,我们无法识别内部网页内容.

此外,当VoiceOver在加载Web内容后第一次启用时,它会执行可以识别Web内容的奇怪行为.

怀疑是VoiceOver内容识别时序的问题,我试了一下运行

UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil)

UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil)

加载网页内容后,却没有得到好的结果.

tableViewVoiceOver 上的 wkwebview 中的内容有没有好的处理方式?

解决方案

那么,我将解释您所看到的行为.本质上,VoiceOver 只会聚焦树中的第一个辅助功能元素.因此,任何作为辅助功能元素的视图都不会将其作为辅助功能元素的子元素设置为焦点.

至于你的情况,我很好奇你的情况.我发现您可能需要提供更多详细信息.当我绘制一个 tableview 时,我在一个视图中绘制了多个 WKWebView,这确实很奇怪.

webview 的典型标记是将 NOTHING 设置为可访问性元素,并让 WebView 确定其中的哪些元素是可访问的.WKWebView 应该负责将 HTML 内容报告为适合您的本机可访问性元素.做任何其他事情都会破坏 WKWebView 正在发生的事情.但是,如果您在一个应用程序中有多个 webviews,这可能会搞砸.最终,如果它没有按照我概述的方式工作(只是将事情搁置一旁,并将所有内容标记为非"可访问性元素),这将是一个错误,但您将不得不处理此错误.

然后,解决方案变为覆盖您的 web 视图的 UIAccessibilityContainer 协议,并为其提供自定义反馈.不理想,会很痛苦.更多细节会有所帮助,但至少现在您可以对正在发生的事情有更多了解.

另一种简单的解决方案是,如果您的 webview 中的内容非常简单,您可以将 accessibility 元素设置为 true,并通过 accessibilityLabel、accessibilityValue 和 accessibilityTraits 提供整个 webview 的内容描述.只要确保您掌握了所有信息,并且任何操作仍然是可操作的!

Normally, VoiceOver correctly reads web contents loaded with WKWebView and it is possible to read buttons and links.

However, when I added WKWebView on UITableViewCell and displayed in UITableVIew, VoiceOver could not recognize it.

According to the tableview document of apple, in order to make each content on UITableViewCell recognized by VoiceOver separately, It is necessary to set isAccessibilityElement of cell to false and set isAccessibilityElement of view to be recognized to be true.

but if isAccesibilityElement ofWKWebView is set to true, view itself is focused and we can not recognize the inside web contents.

Also, when VoiceOver was enabled for the first time after loading the Web content, it performed strange behavior that Web content could be recognized.

I suspected the problem of VoiceOver content recognition timing, I tried running

UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil)

or

UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil)

after loading the web content, but it did not get a good result.

Is there a good way to handle contents in wkwebview on tableView to VoiceOver?

解决方案

So, I'll explain the behavior you're seeing. Essentially, VoiceOver will only focus the first accessibility element in a tree. So any view that is an Accessibility Element will not have its children that are accessibility elements be focused.

Now as for your situation, I'm curious as to your scenario. I find it likely that you need to provide more detail. When I picture a tableview, I picture multiple WKWebViews in one view, which would be weird indeed.

The typical markup for a webview would be to just have NOTHING set as an accessibility element, and let the WebView determine which elements within are accessible. WKWebView should take care of reporting HTML content as proper native accessibility elements for you. To do anything else is going to corrupt what WKWebView is going. HOWEVER, if you have multiple webviews in one app, this may muck things up. Ultimately, if it didn't work the way I outlined (just by leaving things alone, and marking everything as "not" an accessibility element), this would be a bug, but a bug that you would have to deal with.

The solution THEN becomes overriding the UIAccessibilityContainer protocol for your webview, and providing custom feedback for it. Not ideal, would be painful. More details would help, but at least now you can understand a little more about what is going on.

Another simple solution would be, if the content in your webview is very simple, you could set accessibility element to true, and provide a description of the content for the entire webview through the accessibilityLabel, accessibilityValue and accessibilityTraits. Just be sure you catch all of the information, and that any actions are still actionable!

这篇关于如何为 tableview 上的 webview 内容启用 VoiceOver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆