以编程方式确定 VoiceOver 读取 UIView 项目的顺序
我正在使我的 iPhone 应用程序易于访问。 VoiceOver 令人印象深刻。当用户使用 VoiceOver 时,它会自动读出屏幕上的项目,并允许用户双击屏幕上的任意位置来选择该项目。但是,我希望 VoiceOver 按特定顺序读取项目,但它始终从 UINavigationBar 项目(包括后退按钮)开始。我根本不希望这些项目被阅读,我只想从特定项目开始。是否有“firstResponder”的 VoiceOver 等效项?
I am making my iPhone app accessible. VoiceOver is pretty impressive. When a user uses VoiceOver, it automatically reads off the items on the screen and allows the user to double-tap anywhere on the screen to select that item. However, I want VoiceOver to read the items in a specific order, but it always begins with the UINavigationBar items including the back button. I don't want these items not to be read at all, I just want to start with a specific item. Is there a VoiceOver-equivalent of "firstResponder"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,
有一个名为
UIAccessibilityContainer
的协议,它是由 NSObject 实现的。它使您能够使用以下三种方法自定义容器行为:accessibilityElementCount
accessibilityElementAtIndex:
indexOfAccessibilityElement:
如果您有一个要控制的主视图您只需实现这三个方法并返回合适的视图/索引即可访问元素的顺序。另一件事是容器视图本身不能是辅助功能元素,因此您应该覆盖
isAccessibilityElement:
并返回NO
;示例实现
我建议您要么按照您希望的显示顺序拥有所有视图的数组,要么使用
tag
属性(如果您不将其用于其他任何用途)。协议的实现变得超级简单。元素数组
我假设您有一个名为
accessibleElements
的数组,它以正确的顺序存储元素。标记元素
我假设您的子视图从 0 到子视图的数量连续标记。
Yes
There is a protocol called
UIAccessibilityContainer
that is implemented by NSObject. It enables you to customize the container behaviour using these three methods:accessibilityElementCount
accessibilityElementAtIndex:
indexOfAccessibilityElement:
If you have a main view where you want to control the order of the accessibility elements you would just implement these three methods and return the suitable view/index. One more thing is that the container view cannot be an accessibility element itself so you should override
isAccessibilityElement:
and returnNO
;Example implementations
I suggest that you either have an array of all the views in the order you want them to appear or use the
tag
property if you don't use it for anything else. The implementation of the protocol becomes super simple.Array of elements
I'm assuming that you have an array called
accessibleElements
that store the elements in the correct order.Tagged elements
I'm assuming that your subviews are tagged continuously from 0 up to the number of subviews.
在某些情况下,在一项上设置 UIAccessibilityTraitSummaryElement 可以实现此目的。 (我的游戏似乎太动态了,这没有多大帮助。)
In some cases, setting UIAccessibilityTraitSummaryElement on one item can do this. (My game seems too dynamic for this to help much.)
Swift 5 您可以在 accessibilityElements 属性中指定元素的顺序
,用于指定 CollectionView 单元格的顺序。
Swift 5 You can specify the order of element in accessibilityElements property
For specifying the order of CollectionView cells.