iOS VoiceOver 读取 accessibilityIdentifier 而不是 accessibilityLabel

iOS VoiceOver reading accessibilityIdentifier instead of accessibilityLabel

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

VoiceOver 不会朗读 image,而是朗读 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)
        )
    ]

这是因为您在此处将控件类型 (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`.
*/

使用任何值 - 例如 "media" - 这不是对象的特征,因为画外音将读取可访问性标签值,后跟对象的特征控件类型如下:"Media Image".

mediaImageView.accessibilityLabel = "media" /* This should work */

摘自accessibilityLabel Apple Documentation:

Note that the label never includes the control type (such as button) because the traits of the accessibility element contain that information.

mediaImageViewaccessibilityTraits 设置为 UIAccessibilityTraits.button

mediaImageView.accessibilityTraits = UIAccessibilityTraits.button