【问题标题】:Disable VoiceOver on UIButton/UITableViewCell/UICollectionViewCell Selection在 UIButton/UITableViewCell/UICollectionViewCell 选择上禁用 VoiceOver
【发布时间】:2016-05-10 14:34:59
【问题描述】:

打开 VoiceOver 后,当焦点位于 UIButton/UITableViewCell/UICollectionViewCell 时,VoiceOver 会读取它的辅助功能标签一次。

然后,一旦用户双击以选择 UIButton/UITableViewCell/UICollectionViewCell,VoiceOver 会再次读取相同的可访问性标签,除了对 UIButton/UITableViewCell/@987654330 执行操作(导航等) @选择。

我进行了很多搜索,但无法找到一种方法来停止/禁用 VoiceOver 阅读 UIButton/UITableViewCell/UICollectionViewCell 选择上的辅助功能标签。

任何帮助将不胜感激。

【问题讨论】:

  • 你找到答案了吗?我遇到了同样的问题。
  • 抱歉延迟回复。我通过强制选择另一个可访问性元素来处理它。例如,从 TableView/CollectionView 中进行选择后,我应该导航到新的 UI。我正在做的是在导航完成后立即强制选择新 UI 导航栏的左栏按钮项。使用UIAccessibilityPostNotification 进行选择。这样,它开始读取新选择的项目。请参阅此link 进行选择

标签: ios accessibility voiceover


【解决方案1】:

斯威夫特 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

【讨论】:

    【解决方案2】:

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

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

    class BoutonLabelDoubleTap: UIButton {
    
        override func accessibilityActivate() -> Bool {
            accessibilityLabel = ""
            return true
        }
    }
    

    UITABLEVIEWCELL:要遵循的两个步骤。

    • 创建一个覆盖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 的基本原理相同。

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

    【讨论】:

    • 我们如何停止“1 of 10”、“2 of 10”等的语音。在 UIPickerView 中遇到问题,每当我们滑动到任何元素时,它总是显示“1 of 10”跨度>
    • @Nishchith 在我提供的这个可滚动视图示例中,我不确定您是否会为每个单元格听“1 over x”,不是吗? (现在已经超过 2 年了⏳)我没有用选择器视图进行任何测试,我提供的唯一答案是 stackoverflow.com/a/61018428/3825084,对不起。
    • 当然谢谢。我正面临当前索引未正确表达的问题。当我滑动时,它总是显示“总共 1”。您知道只有在选择器滑动发生时我们才能完全禁用画外音吗?关于设置我自己的accessibilityLabel。它发出可访问性标签文本,然后是默认文本。 stackoverflow.com/questions/68183280/…
    猜你喜欢
    • 1970-01-01
    • 2017-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-08
    • 2015-10-11
    • 2011-04-05
    • 1970-01-01
    相关资源
    最近更新 更多