我正在为我们的iOS应用程序(在Swift中)支持辅助功能。我有UITableViewCell
s的内CollectionView
(每个细胞内的ImageView),它看起来像这样:带有内部CollectionView的TableViewCell上的iOS辅助功能
默认情况下,当我在父视图点击(TableViewCell),它读取2个标签,当我点击CollectionView单元格时,它会读取单元格中图像的名称。但是,某些标签和图像具有不同的可访问性值,因此我必须手动设置它们。
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if let tableViewCell = cell as? MyParentTableView {
tableViewCell.isAccessibilityElement = true
tableViewCell.accessibilityLabel = getCorrectAccessibilityLabel()
}
}
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
// sample only
if let myCell = cell as? MyCollectionViewCell {
myCell.isAccessibilityElement = true
myCell.accessibilityValue = getCorrectAccessibilityLabel()
}
}
当我这样做,父视图块整体视图,这样我就可以不再专注于细胞的CollectionView的辅助框和配音不读出来了。我试着先设置TableView的可访问性,然后设置每个CollectionView单元格的可访问性,并在TableView中使用accessibilityElements
,但似乎没有工作。
// TableViewCell's awakeFromNib function
override func awakeFromNib() {
super.awakeFromNib()
self.collectionView.dataSource = self
self.collectionView.delegate = self
self.accessibilityElements = [self, self.collectionView]
}
编辑:发表了一些代码。
感谢任何帮助或见解。谢谢!