随着VoiceOver的开启,当焦点出现在UIButton
/ UITableViewCell
/ UICollectionViewCell
上时,VoiceOver会读取它的可访问性标签一次。
然后,只要用户双击选择UIButton
/ UITableViewCell
/ UICollectionViewCell
,除了在UIButton
/ UITableViewCell
/ UICollectionViewCell
选择上执行动作(导航等)之外,VoiceOver再次读取相同的辅助功能标签。
我搜索了很多,但无法在UIButton
/ UITableViewCell
/ UICollectionViewCell
选择中找到停止/禁用VoiceOver读取辅助功能标签的方法。
任何帮助将受到高度赞赏。
让我们看看如何停止UIButton
和UITableViewCell
元素的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在选择时是否应该停止读取所需的元素标签。