创建自定义 VoiceOver 转子以垂直导航 UICollectionView

Creating custom VoiceOver rotor to navigate UICollectionView vertically

我有一个大的方形网格(225 个单元格)构造为 2d UICollectionView,我希望盲人用户能够轻松地在网格中导航。目前,他们需要水平滚动每个方块才能向下移动。理想情况下,我想要一个自定义的 VoiceOver 转子,它允许左右滑动以进行导航。这可能吗?

如果没有,我会满足于拥有一个通过 left/right 滑动上下移动的自定义转子。我试图通过获取当前 indexPath 并使用 scrollToItem 方法来更改它来创建一个。转子可以选择,但目前没有效果所以我到目前为止做错了。

private func setupVerticalRotor() -> UIAccessibilityCustomRotor {

    let vertRotorOption = UIAccessibilityCustomRotor.init(name: "Move vertically") { (predicate) -> UIAccessibilityCustomRotorItemResult? in

        let forward = predicate.searchDirection == UIAccessibilityCustomRotor.Direction.next
        let visibleCells = self.collectionView.visibleCells
        if let firstCell = visibleCells.first {
            if let indexPath = self.collectionView.indexPath(for: firstCell as UICollectionViewCell) {
                if forward {
                    let newIndexPath = IndexPath(row: indexPath.row, section: indexPath.section + 1)
                    self.collectionView.scrollToItem(at: newIndexPath, at: UICollectionView.ScrollPosition.centeredVertically, animated: false)

                }else {
                    let newIndexPath = IndexPath(row: indexPath.row, section: indexPath.section - 1)
                    self.collectionView.scrollToItem(at: newIndexPath, at: UICollectionView.ScrollPosition.centeredVertically, animated: false)
                }
            }
        }
        return UIAccessibilityCustomRotorItemResult.init(targetElement: self.collectionView , targetRange: nil)
    }
    return vertRotorOption
}

Ideally, I'd like to have a custom VoiceOver rotor that allows for left, right, up and down swiping to navigate. Is this possible?

本机转子已经有垂直导航的项目。

对于您的代码,我建议看一下 this custom rotor example + 检查您的集合视图单元格是否在 Xcode 中使用断点更新。