我正在爲我們的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]
}
編輯:發表了一些代碼。
感謝任何幫助或見解。謝謝!