iOS 旁白阅读accessibilityIdentifier 而不是accessibilityLabel

Ben*_*van 5 accessibility ios voiceover swift

VoiceOver 应该读取accessibilityLabel屏幕上任何辅助功能元素的属性。我有一个UIImageView调用mediaImageView,下面的代码在此视图上设置可访问性,并awakeFromNibUITableViewCell子类中调用。

imageVoiceOver不是阅读,而是阅读articleMediaCell_image哪个是accessibilityIdentifier. 谁能解释为什么会发生这种情况?

(在 iOS 13.3 设备上测试,无论是否设置自定义操作都会出现问题)

    mediaImageView.isAccessibilityElement = true
    mediaImageView.accessibilityIdentifier = "articleMediaCell_image"
    mediaImageView.accessibilityLabel = "image"

    mediaImageView.accessibilityCustomActions = [
        UIAccessibilityCustomAction(
            name: "expand to fullscreen",
            target: self,
            selector: #selector(imageTapped)
        )
    ]
Run Code Online (Sandbox Code Playgroud)

bad*_*esh 5

发生这种情况是因为您已将控件类型 (UIImage) 的特征(图像)设置为accessibilityLabel此处的值:

mediaImageView.accessibilityLabel = "image"
/*
Won't work, because iOS already knows that this is an image from the element's traits.
Due to this, the redundant value is ignored and the voiceover falls back to reading the `accessibilityIdentifier`.
*/
Run Code Online (Sandbox Code Playgroud)

使用任何值 -例如“媒体” - 不是对象的特征,因为画外音将读取可访问性标签值,然后是控件类型的特征,如下所示:“媒体图像”

mediaImageView.accessibilityLabel = "media" /* This should work */
Run Code Online (Sandbox Code Playgroud)

accessibilityLabel 苹果文档摘录:

但是请注意,标签不应包含控件类型(例如“按钮”),因为此信息包含在与可访问性元素关联的特征中。