简体   繁体   English

带有内部CollectionView的TableViewCell上的iOS可访问性

[英]iOS Accessibility on TableViewCell with inner CollectionView

I'm working on supporting Accessibility for our iOS app (in Swift). 我正在努力为我们的iOS应用程序(在Swift中)支持辅助功能。 I have UITableViewCell s with an inner CollectionView (with inner ImageView per cell), which looks like this: 我有UITableViewCell的内部CollectionView (每个单元格有内部ImageView),如下所示:

在此输入图像描述

By default, when I tap on the parent view (TableViewCell), it reads the 2 labels, and when I tap on the CollectionView cells, it reads the name of the image in the cell. 默认情况下,当我点击父视图(TableViewCell)时,它会读取2个标签,当我点击CollectionView单元格时,它会读取单元格中图像的名称。 However, some labels and images have different accessibility values, so I had to set them manually. 但是,某些标签和图像具有不同的可访问性值,因此我必须手动设置它们。

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()
    }
} 

When I did that, the parent view blocks the whole view, so I can no longer focus the accessibility box on the CollectionView cells and VoiceOver does not read them out anymore. 当我这样做时,父视图会阻止整个视图,因此我无法再将可访问性框集中在CollectionView单元格上,而且VoiceOver不会再将它们读出来。 I tried setting the TableView's accessibility first, then the accessibility of each CollectionView cell, and also using accessibilityElements in the TableView, but it does not seem to be working. 我首先尝试设置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]
}

EDIT: Posted some code. 编辑:发布一些代码。

Appreciate any help or insight. 感谢任何帮助或见解。 Thanks! 谢谢!

If I understood the problem is that you can't click on the collection because always the app thinks that you click on the row, right? 如果我明白问题是你无法点击该集合,因为应用程序总是认为你点击了这行,对吗? Have you tried to disable the selection of the row and put a invisible view under the collection with the same width and height of the row and with a touchRecognition? 您是否尝试禁用行的选择并在集合下放置一个不可见的视图,该视图具有相同的行宽和高度以及touchRecognition? If you click on the view is like you clicked on the row, but I think this can solve your problem. 如果你单击视图就像你点击了行,但我认为这可以解决你的问题。

One other tip: Don't put the settings of the delegate in the awakeFromNib method, because sometimes this method is not called. 另一个提示:不要将委托的设置放在awakeFromNib方法中,因为有时候不会调用此方法。 It depends on the objects created. 这取决于创建的对象。 Put it always in the viewDidLoad(). 将它始终放在viewDidLoad()中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM