无法将画外音焦点转移到特定的UICollectionView单元格



我使用以下经过尝试和测试的代码来让VoiceOver选择特定的UICollectionViewCell:

var indexPath = IndexPath(row: 4, section: 3)
if let cell = self.collectionView.cellForItem(at: indexPath) {
UIAccessibility.post(notification: UIAccessibility.Notification.screenChanged,
argument: cell)
}

然而,无论我将索引路径设置为什么单元格,VoiceOver都会忽略这一点,并始终最终选择最后选择的UICollectionViewCell。即使我事先使用:

取消选择单元格
self.collectionView.selectItem(at: nil, animated: false, scrollPosition: .bottom)

问题1。有人遇到过这个问题吗?2. 这是另一个VoiceOver bug吗?3.有人有解决办法吗?

首先,确保您的单元格启用了可访问性,并且它们具有有效的可访问性标签。

作为测试实现,我在UICollectionViewDataSourcecellForItemAt方法中添加了以下代码:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kCellIdentifier, for: indexPath)

let numberOfCells = 100

// Set these values if you haven't
cell.isAccessibilityElement = true
cell.accessibilityLabel = "Cell (indexPath.item) of (numberOfCells))"

return cell
}

注意:当collectionView也有可访问性启用时,我遇到了麻烦。当只有单元格具有可访问性时,VoiceOver工作正常。

接下来,尝试调用初始方法来获取VoiceOver以选择集合视图单元格。我通过首先从collectionView的selectItem方法中选择单元格获得了一些额外的平滑,如下所示。

var indexPath = IndexPath(row: 4, section: 3)
if let cell = self.collectionView.cellForItem(at: indexPath) {
self.collectionView.selectItem(
at: indexPath,
animated: true,
scrollPosition: [.centeredVertically, .centeredHorizontally]
)
UIAccessibility.post(
notification: UIAccessibility.Notification.screenChanged,
argument: cell
)
}

最新更新