簡體   English   中英

在 UIButton/UITableViewCell/UICollectionViewCell 選擇上禁用 VoiceOver

[英]Disable VoiceOver on UIButton/UITableViewCell/UICollectionViewCell Selection

打開 VoiceOver 后,當焦點出現在UIButton / UITableViewCell / UICollectionViewCell ,VoiceOver 會讀取它的輔助功能標簽一次。

然后,只要用戶雙擊以選擇UIButton / UITableViewCell / UICollectionViewCell ,VoiceOver 除了在UIButton / UITableViewCell / UICollectionViewCell選擇上執行操作(導航等)之外, UICollectionViewCell再次讀取相同的輔助功能標簽。

我已經搜索了很多,但無法找到一種方法來停止/禁用UIButton / UITableViewCell / UICollectionViewCell選擇上的 VoiceOver 閱讀輔助功能標簽。

任何幫助將不勝感激。

斯威夫特 5

對我myElementIWantSilent.accessibilityTraits = .none是設置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

讓我們看看如何停止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 在選擇時是否應停止讀出所需的元素標簽

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM