简体   繁体   English

如何使用适当的可访问性修饰符覆盖 SwiftUI 选择器

[英]How to cover SwiftUI Picker with a proper accessibility modifiers

I have a SwiftUI Picker:我有一个 SwiftUI 选择器:

Picker(selection: self.$selectedIndex, label: Text("")) {
    Text("△").font(.system(size: 20)).tag(0)
    Text("□").font(.system(size: 20)).tag(1)
    Text("○").font(.system(size: 20)).tag(2)
}.pickerStyle(SegmentedPickerStyle())

Want to make it accessible for VoiceOver.想让 VoiceOver 可以访问它。 Tried to do the following:尝试执行以下操作:

Picker(selection: self.$selectedIndex, label: Text("")) {
    Text("△").font(.system(size: 20)).tag(0).accessibility(label: Text("Triangle label"))
    Text("□").font(.system(size: 20)).tag(1).accessibility(label: Text("Square label"))
    Text("○").font(.system(size: 20)).tag(2).accessibility(label: Text("Circle label"))
}.pickerStyle(SegmentedPickerStyle())

Accessibility inspector shows label="△" but I expect it should show label="Triangle label".辅助功能检查器显示 label="△" 但我希望它应该显示 label="Triangle label"。

Please help to find out the proper solution.请帮助找出正确的解决方案。

I have a similar problem, I filed it with Apple as FB8806682.我有一个类似的问题,我将它作为 FB8806682 提交给 Apple。 I noticed two interesting factors, at least on iOS 14.我注意到两个有趣的因素,至少在 iOS 14 上。

  1. This only happens when using the SegmentedPickerStyle() .这只发生在使用SegmentedPickerStyle()时。 A default picker will correctly read the provided labels.默认选择器将正确读取提供的标签。

  2. If you activate any control on the screen (including the picker itself.) then the segmented picker will start reading the proper labels.如果您激活屏幕上的任何控件(包括选取器本身。)然后分段选取器将开始读取正确的标签。

As part of the Feedback Assistant entry I created a sample app that shows the two pickers and demonstrates the difference.作为反馈助手条目的一部分,我创建了一个示例应用程序,它显示了两个选择器并演示了差异。 It's available on GitHub as well.它也适用于 GitHub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM