如何使 VoiceOver 将 UITableView 视为单个可访问性元素?
How to make VoiceOver treat a UITableView as a single accessibility element?
在一个特殊的用例中,我希望 UITableView
成为单个可访问性元素,而不是将其单元格暴露给 VoiceOver
的容器。
我尝试将它的 isAccessibilityElement
设置为 true
并分配它的 accessibilityLabel
但它没有用。
I want a UITableView
to be a single accessibility element instead of a container exposing its cells to VoiceOver
.
不幸的是,这是不可能的。
您可以在没有警告的情况下对其进行编码,因为您处理的是非正式协议,但它不会被 VoiceOver
解释:这是一团糟,因为您在 tableView
上做的事情与在简单的 label
例如,但它在这里不起作用。
我没有技术证明,但我认为 tableView
并不意味着是一个可访问的元素,只有它的单元格应该。
I tried setting its isAccessibilityElement to true and assigning its accessibilityLabel but it didn't work [...] when I swipe left and right, VoiceOver goes through the cells and doesn't pronounce the table view's accessibilityLabel
.
一个 UITableView
可以被看作是一个容器,里面嵌入了许多元素 (它的单元格) 而且,照原样,你不能同时有一个父元素视图 (table 视图) 及其子视图 (其单元格) both accessible 使用 VoiceOver: table 可以选择视图或其单元格。
如果您不想滑动单元格,请在后面插入代码片段:
myTableViewInsideTheCell.accessibilityElementsHidden = true
然后,VoiceOver
被告知不能解释 table 视图中的元素。
现在,由于 table 视图不能被视为可访问元素,只需在 table 视图单元格中创建一个:
let a11yElt = UIAccessibilityElement(accessibilityContainer: myTableViewCell.contentView)
a11yElt.accessibilityFrameInContainerSpace = myTableViewInsideTheCell.frame
a11yElt.accessibilityTraits = .staticText
a11yElt.accessibilityLabel = "my table view inside the cell is now accessible."
myTableViewCell.accessibilityElements = [a11yElt]
此元素与单元格内的 table 视图重叠,可被视为具有共同属性的任何其他可访问元素。
我认为还有许多其他方法可以达到您的目标,但是,根据这个基本原理,您可以让 VoiceOver 将 UITableView 视为单个可访问性元素。
您已经有了指南,现在由您来 implement/adapt 在您的环境中实现您的目标。
在一个特殊的用例中,我希望 UITableView
成为单个可访问性元素,而不是将其单元格暴露给 VoiceOver
的容器。
我尝试将它的 isAccessibilityElement
设置为 true
并分配它的 accessibilityLabel
但它没有用。
I want a
UITableView
to be a single accessibility element instead of a container exposing its cells toVoiceOver
.
不幸的是,这是不可能的。
您可以在没有警告的情况下对其进行编码,因为您处理的是非正式协议,但它不会被 VoiceOver
解释:这是一团糟,因为您在 tableView
上做的事情与在简单的 label
例如,但它在这里不起作用。
我没有技术证明,但我认为 tableView
并不意味着是一个可访问的元素,只有它的单元格应该。
I tried setting its isAccessibilityElement to true and assigning its accessibilityLabel but it didn't work [...] when I swipe left and right, VoiceOver goes through the cells and doesn't pronounce the table view's
accessibilityLabel
.
一个 UITableView
可以被看作是一个容器,里面嵌入了许多元素 (它的单元格) 而且,照原样,你不能同时有一个父元素视图 (table 视图) 及其子视图 (其单元格) both accessible 使用 VoiceOver: table 可以选择视图或其单元格。
如果您不想滑动单元格,请在后面插入代码片段:
myTableViewInsideTheCell.accessibilityElementsHidden = true
然后,VoiceOver
被告知不能解释 table 视图中的元素。
现在,由于 table 视图不能被视为可访问元素,只需在 table 视图单元格中创建一个:
let a11yElt = UIAccessibilityElement(accessibilityContainer: myTableViewCell.contentView)
a11yElt.accessibilityFrameInContainerSpace = myTableViewInsideTheCell.frame
a11yElt.accessibilityTraits = .staticText
a11yElt.accessibilityLabel = "my table view inside the cell is now accessible."
myTableViewCell.accessibilityElements = [a11yElt]
此元素与单元格内的 table 视图重叠,可被视为具有共同属性的任何其他可访问元素。
我认为还有许多其他方法可以达到您的目标,但是,根据这个基本原理,您可以让 VoiceOver 将 UITableView 视为单个可访问性元素。
您已经有了指南,现在由您来 implement/adapt 在您的环境中实现您的目标。