iOS TableViewCell 中 CollectionView 的辅助功能

iOS Accessibility for CollectionView in a TableViewCell

我目前正在研究我们项目的可访问性,这里是放入自定义 UITableViewCell 的 UICollectionView。此 CollectionView 有数十个单元格,它们排列成多行而不是一行。

它提出了一个问题,当你打开 voiceOver 并通过向左或向右滑动在 collectionViewCells 之间移动焦点时,系统认为你在 tableViewCells 之间滑动,因为 collectionView 在 tableView 中,以及 tableView 的 contentOffSet将根据 tableViewCell 大小而不是 collectionViewCell 大小进行更改。

CollectionView 已经放在 tableView 中,我认为我无法更改它。所以只是想知道以前有没有人遇到过这种情况,无论如何都可以使 collectionView 正常访问?

只需通过重建整个页面来解决问题,为了让您的应用更易于访问,请不要做以下两件事:

  1. 避免直接向 tableView/collectionView 添加子视图,例如

    [tableView/collectionView addSubview:yourSubView];

  2. 避免将可垂直滚动的 collectionView 添加到 tableViewCell。

    向 tableViewCell 添加可水平滚动的 collectionView 似乎不会引起任何问题。

这是在 tableView 中嵌套 collectionView 时 Apple SDK 中的一个已知错误(抱歉,我没有错误报告参考)。经过一些实验,我能够通过使用 UIView 作为我的 collectionView 的包装器来解决它,然后再将它添加到我的 UITableViewCell 的 .contentView

    UIView *wrapperView = [[UIView alloc] initWithFrame:cell.contentView.bounds];
    wrapperView.accessibilityElements = @[collectionView];
    [cell.contentView addSubview:wrapperView];
    [wrapperView addSubview:collectionView];