VoiceOver 是否总是忽略宽度和高度为零 iOS 的视图?

Does VoiceOver always ignore views with width and height zero iOS?

Voice Over 忽略 UILabel 是否足以将其文本 属性 设置为 nil 或者是否还需要设置 isHidden 属性 也为真 ?

我在示例项目中对此进行了测试,发现当文本设置为 nil 时,Voice Over 会忽略标签。我可以一直指望这个吗?在这种情况下,标签的宽度和高度将为零,因为我没有添加任何约束。那么我是否可以假设任何宽度和高度为零的视图都会被 Voice Over 忽略,无论它是否隐藏?

In order for it [UILabel] to be ignored by VoiceOver is setting text to nil enough or should I also set the isHidden property to true as well?

对于要被 VoiceOver 忽略的元素,适当的方法将其 isAccessibilityElement 属性 设置为 false ...除其他方法外,这取决于您使用的元素 ⟹ UILabel 就足够了。
在这种情况下,将其文本设置为 nil 是可行的,但与其说是正确的解决方案,不如说是一种混乱。

图形元素不应仅在 VoiceOver 为 运行 时消失,因为 您的界面应该对每个人都相同:例如,您可能有不识字的人可以在有或没有 VoiceOver 的情况下使用您的应用程序,如果他们在两种方式上没有相同的视觉体验,他们可能会感到困惑。

I tested this in a sample project and saw that Voice Over ignores the label when the text is set to nil. Can I always count on this?

不,你不能,因为它适用于 UILabel,但如果你尝试对按钮或文本字段执行相同的操作,你你会注意到它肯定不会工作,因为它们 'accessibilityTraits`.

So can I assume that any view with a width and height of zero would be ignored by Voice Over irrespective of whether it is hidden or not?

是的,你可以因为{width = height = zero}意味着这个元素不是 VoiceOver 应该分析和读出的图形元素。
但是,即使可行,我不建议按照此路径 将元素隐藏到 VoiceOver,正如我之前解释的那样。