在一个特殊的用例中,我想要一个 UITableView
成为单个可访问性元素,而不是将其单元格暴露给 VoiceOver
的容器.
我尝试设置它的isAccessibilityElement
至true
并分配其accessibilityLabel
但它没有用。
最佳答案
I want a
UITableView
to be a single accessibility element instead of a container exposing its cells toVoiceOver
.
不幸的是,这是不可能的 .😨
您可以在没有警告的情况下对其进行编码,因为您处理的是非正式协议(protocol),但它不会被
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
可以被视为一个容器,其中嵌入了许多元素(它的单元格),并且,您不能同时拥有一个父 View (表格 View )和它的 subview (它的单元格)both accessible使用 VoiceOver:可以选择表格 View 或其单元格。如果您不想在单元格中滑动,请在下面插入代码片段:
myTableViewInsideTheCell.accessibilityElementsHidden = true
然后,
VoiceOver
被告知不能解释 TableView 中的元素。现在,由于表格 View 不能被视为可访问的元素,只需在表格 View 单元格中创建一个:
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]
该元素与单元格内的表格 View 重叠,并且可以被视为具有公共(public)属性的任何其他可访问元素。 👍
我认为有许多其他方法可以实现您的目标,但是按照这个原理,您可以 使 VoiceOver 将 UITableView 视为单个可访问性元素 .
您有指南,现在由您在您的环境中实现/调整它以实现您的目标。😉
关于ios - 如何让 VoiceOver 将 UITableView 视为单个可访问性元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60406769/