堆栈视图中控件的可访问性 [英] Accessibility for controls in stack view
问题描述
我有一个带有按钮和水平标签的水平堆栈视图
I have a horizontal stackview with a button and label horizontally
当我打开画外音时,这些按钮中的文字根本无法朗读.所有其他工作正常.
When I turn on voice over, text in these buttons are not reading at all. All others works fine.
下面是我如何设置我的代码.请指导如何启用这些.不知道为什么这不起作用
Below is how i setup my code. Please guide how to enable these. Not sure why this isn't working
我的按钮文本和标签文本采用动态值
I have my button text and label text taking dynamic values
此外,如果有任何信息为什么使用accessibilityIdentifier 真的会有所帮助.我找不到对此的明确解释
self.myHorizontalStackView.isAccessibilityElement = true
//Accessibility for Button
self.submitButton.isAccessibilityElement = true
self.submitButton.accessibilityTraits = UIAccessibilityTraitStaticText
self.submitButton.accessibilityLabel = screenControls.buttonTitle
//Accessibility for Label
self.addressLabel.isAccessibilityElement = true
self.addressLabel.accessibilityTraits = UIAccessibilityTraitStaticText
self.addressLabel.accessibilityLabel = screenControls.address1
推荐答案
所以问题看起来像是来自您的 stackView
本身.请参阅此关于该主题的其他 SO 问题/答案:
So the problem looks like it's coming from your stackView
itself. See this other SO question/answer on the subject:
如果容器视图是可访问的,它的子视图通常会被遮住,以避免混淆用户试图与之交互的内容.
If a container view is accessible, its child views are often obscured to avoid confusion about what the user is trying to interact with.
所以在这里,更改您共享的代码段中的第一行:
So here, change your first line in the snippet you shared to:
self.myHorizontalStackView.isAccessibilityElement = false
这应该能让 VoiceOver 找到 stackView
的子视图.
and that should enable VoiceOver to find the subviews of the stackView
.
至于你的另一个问题:
此外,如果有任何信息为什么使用了 accessibilityIdentifier 也会真正有帮助.我找不到对此的明确解释
如果您询问标识符的用途,主要是为了测试目的.通过为您的视图设置唯一标识符,您的测试可以轻松地使用可访问性引擎来查找特定视图并执行您想要测试的任何操作.就 VoiceOver 而言,accessibilityIdentifier
没有作用.
If you are asking what the identifier would be used for, it's primarily for testing purposes. By setting unique identifiers to your views, your tests can easily use the accessibility engine to find specific views and perform any actions you'd want to test. In terms of VoiceOver, the accessibilityIdentifier
does not have a role.
这篇关于堆栈视图中控件的可访问性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!