UIAutomation嵌套的Accessibilty元素从层次结构中消失 [英] UIAutomation Nested Accessibilty Elements Disappear from Hierarchy
问题描述
我有一个包含按钮和图像的两个子视图的视图,我打开辅助功能并在子视图上设置标签,我可以通过调用
$ b <$ p来查看层次结构$ p>
UIATarget.localTarget()frontMostApp()主窗口()logElementTree()。;
我得到以下例子:
1窗口
2我的观点
3我的按钮
3我的图像
如果我打开辅助功能并为我父母设置标签我无法再在层次结构中的任何位置看到我的按钮和图像。
我得到:
1窗口
2我的观点
为什么我的观点消失了吗?
直接来自iOS文档辅助功能指南
使自定义容器视图的内容可访问
如果您的应用程序on将显示包含用户与之交互的其他元素的自定义视图,您需要单独访问所包含的元素。同时,您需要确保无法访问容器视图本身。原因是用户与容器的内容进行交互,而不是与容器本身进行交互。
为实现此目的,您的自定义容器视图应实现UIAccessibilityContainer协议。此协议定义了使包含的元素在数组中可用的方法。
以下代码段显示了自定义容器视图的部分实现。请注意,只有在调用UIAccessibilityContainer协议的方法时,此容器视图才会创建可访问元素的数组。因此,如果iPhone辅助功能当前未处于活动状态,则不会创建该阵列。
I have a view with two subviews a button and an Image, I turn on accessibility and set the label on the subviews and I can see the hierarchy by calling
UIATarget.localTarget().frontMostApp().mainWindow().logElementTree();
I get the following for example:
1 Window
2 My View
3 My Button
3 My Image
If I then turn on accessibility and set the label for my parent view I can no longer see my button and image anywhere in the hierarchy.
I just get:
1 Window
2 My View
Why have my views disappeared?
Straight from the iOS docs Accessibility Guide
Make the Contents of Custom Container Views Accessible If your application displays a custom view that contains other elements with which users interact, you need to make the contained elements separately accessible. At the same time, you need to make sure that the container view itself is not accessible. The reason is that users interact with the contents of the container, not with the container itself.
To accomplish this, your custom container view should implement the UIAccessibilityContainer protocol. This protocol defines methods that make the contained elements available in an array.
The following code snippet shows the partial implementation of a custom container view. Note that this container view creates the array of accessible elements only when methods of the UIAccessibilityContainer protocol are called. As a result, if iPhone accessibility is not currently active, the array is not created.
这篇关于UIAutomation嵌套的Accessibilty元素从层次结构中消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!