VoiceOver正在寻找附近的可读元素以进行阅读? [英] VoiceOver is finding a nearby accessible element to read?

查看:133
本文介绍了VoiceOver正在寻找附近的可读元素以进行阅读?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的iOS应用添加可访问性。我看到一种特定的情况,当我点击具有 isAccessibilityElement = false 的UIView时,其所有祖先视图也都是 isAccessibilityElement = false ,VoiceOver会说出该视图的兄弟姐妹的文字-该视图的父级的另一个子级。在Accessibility Inspector中,当我将鼠标悬停在此视图上时,兄弟姐妹会亮起来。

I'm adding accessibility to my iOS app. I'm seeing a specific situation that when I tap on a UIView that has isAccessibilityElement = false, and all of its ancestor views are also isAccessibilityElement = false, VoiceOver will speak the text from this view's sibling - a different child of this view's parent. And in Accessibility Inspector, when I hover over this view, the sibling lights up.

我不明白某些视图不在我的视图层次结构中m点击可用于VoiceOver文本。我没有看到针对iOS 11记录的此类行为。

I don't understand how some view that's not in the hierarchy of the one I'm tapping on could be used for VoiceOver text. I don't see any behavior like this documented for iOS 11. How could this be happening?

编辑:我创建了一个简单的一个带有UITableView的项目,其中包含UITableViewCell对象,每个对象都包含一个UILabel。点击UITableViewCell(位于UILabel外部)将读取其中的UILabel。如何禁用该行为,以便仅点击标签本身而不是包含UITableViewCell的标签,才能读取标签?

I've created a simple project with a UITableView, containing UITableViewCell objects, each of which contains a UILabel. Tapping on a UITableViewCell (outside the UILabel) will read the UILabel within it. How do I disable that behavior, so that only tapping on the label itself, not on its containing UITableViewCell, will read the label?

推荐答案

不能同时访问表格视图单元格(容器)及其内容(子级)(说明此处)。

A table view cell (container) and its content (children) cannot be accessible all together (explanation here).

按照以下步骤回答您的编辑问题,以便仅点击标签本身,而不是点击包含 UITableViewCell 的标签,标签

Follow the steps hereunder to answer your edit mention so that only tapping on the label itself, not on its containing UITableViewCell, will read the label.


  • 创建自己的 UITableViewCell

class TestTableViewCell: UITableViewCell {

    @IBOutlet weak var myLabel: UILabel!

    override var accessibilityTraits: UIAccessibilityTraits {
        get { return UIAccessibilityTraitNone }
        set {}
    }
}


  • 在单元实现中将其标签定义为 UIAccessibilityElement accessibilityElements 数组。

    func tableView(_ tableView: UITableView,
                   cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    
            let zeCell = tableView.dequeueReusableCell(withIdentifier: "myPersoCell",
                                                       for: indexPath) as! TestTableViewCell
    
            zeCell.accessibilityElements = nil
    
            var elements = [UIAccessibilityElement]()
    
            let contentA11yElt = UIAccessibilityElement(accessibilityContainer: zeCell)
            contentA11yElt.accessibilityTraits = UIAccessibilityTraitStaticText
            contentA11yElt.accessibilityFrameInContainerSpace = zeCell.contentLabel.frame //To be adapted
            contentA11yElt.accessibilityLabel = "label content"
    
            elements.append(contentA11yElt)
            zeCell.accessibilityElements = elements
    
            return zeCell
        }
    


  • 按照这些代码段,可以选择位于表格视图单元格内的标签,并根据需要读出其内容

    Following these code snippets will allow to select a label located inside a table view cell and to read out its content as desired.

    这篇关于VoiceOver正在寻找附近的可读元素以进行阅读?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆