VoiceOver打开后,当焦点出现在UIButton
/UITableViewCell
/UICollectionViewCell
上时,VoiceOver读取其辅助功能标签一次。
然后,一旦用户双击选择UIButton
/UITableViewCell
/UICollectionViewCell
,VoiceOver除了对UIButton
/UITableViewCell
/UICollectionViewCell
选择执行操作(导航等)外,还会再次读取相同的可访问性标签。
我搜索了很多,但找不到一种方法来停止/禁用UIButton
/UITableViewCell
/UICollectionViewCell
选择上的VoiceOver阅读辅助功能标签。
如有任何帮助,我们将不胜感激。
让我们看看如何停止对UIButton
和UITableViewCell
元素的VoiceOver辅助功能读取。
UIBUTTON:只需创建自己的按钮类并覆盖accessibilityActivate
方法。
class BoutonLabelDoubleTap: UIButton {
override func accessibilityActivate() -> Bool {
accessibilityLabel = ""
return true
}
}
UITABLEVIEW CELL:需要遵循两个步骤。
创建一个覆盖
accessibilityActivate
方法的自定义UIAccessibilityElement
。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是否应该在选择时停止读取所需的元素标签。
Swift 5
对我有效的是设置myElementIWantSilent.accessibilityTraits = .none
编辑:我应该注意到这些也存在:
viewContainingSilentElement.isAccessibilityElement = true
viewContainingSilentElement.accessibilityTraits = .image
viewContainingSilentElement.accessibilityLabel = "some text i want read aloud"
iPhone 8
iOS 14.5.1
XCode 12.5
在我提出这个问题时,这对我有效(一种变通方法,而不是正确的解决方案)
我通过强制选择另一个可访问性元素来处理它。例如,在从TableView/CollectionView中进行选择之后,我应该导航到新的UI。我所做的是在导航完成后立即强制选择新UI导航栏的左栏按钮项。使用UIAccessibilityPostNotification
进行选择。通过这种方式,它开始读取新选择的项目。请参阅此链接以选择