在UIButton / UITableViewCell / UICollectionViewCell选择上禁用VoiceOver

问题描述 投票:3回答:1

随着VoiceOver的开启,当焦点出现在UIButton / UITableViewCell / UICollectionViewCell上时,VoiceOver会读取它的可访问性标签一次。

然后,只要用户双击选择UIButton / UITableViewCell / UICollectionViewCell,除了在UIButton / UITableViewCell / UICollectionViewCell选择上执行动作(导航等)之外,VoiceOver再次读取相同的辅助功能标签。

我搜索了很多,但无法在UIButton / UITableViewCell / UICollectionViewCell选择中找到停止/禁用VoiceOver读取辅助功能标签的方法。

任何帮助将受到高度赞赏。

ios accessibility voiceover
1个回答
0
投票

让我们看看如何停止UIButtonUITableViewCell元素的VoiceOver辅助功能读取。

UIBUTTON:只需创建自己的按钮类并覆盖accessibilityActivate方法。

class BoutonLabelDoubleTap: UIButton {

    override func accessibilityActivate() -> Bool {
        accessibilityLabel = ""
        return true
    }
}

UITABLEVIEWCELL:要遵循的两个步骤。

  • 创建一个自定义UIAccessibilityElement覆盖accessibilityActivate方法。 class TableViewCellLabelDoubleTap: UIAccessibilityElement { override init(accessibilityContainer container: Any) { super.init(accessibilityContainer: container) } override var accessibilityTraits: UIAccessibilityTraits { get { return UIAccessibilityTraitNone } set { } } override func accessibilityActivate() -> Bool { accessibilityLabel = "" return true } }
  • 使用先前创建的类在视图控制器中实现表视图单元格。 class TestButtonTableViewController: UIViewController,UITableViewDataSource,UITableViewDelegate { @IBOutlet weak var myTableView: UITableView! @IBOutlet weak var bottomButton: UIButton! override func viewDidLoad() { super.viewDidLoad() myTableView.delegate = self as UITableViewDelegate myTableView.dataSource = self as UITableViewDataSource } func numberOfSections(in tableView: UITableView) -> Int { return 1 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 2 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let zeCell = tableView.dequeueReusableCell(withIdentifier: "myPersoCell", for: indexPath) zeCell.accessibilityElements = nil var elements = [UIAccessibilityElement]() let a11yEltCell = TableViewCellLabelDoubleTap(accessibilityContainer: zeCell) a11yEltCell.accessibilityLabel = "cell number " + String(indexPath.row) a11yEltCell.accessibilityFrameInContainerSpace = CGRect(x: 0, y: 0, width: zeCell.contentView.frame.size.width, height: zeCell.contentView.frame.size.height) elements.append(a11yEltCell) zeCell.accessibilityElements = elements return zeCell } }

我没有尝试过UICollectionViewCell,但它应该与UITableViewCell的理由相同。

按照这些代码段,您现在可以决定VoiceOver在选择时是否应该停止读取所需的元素标签。

© www.soinside.com 2019 - 2024. All rights reserved.