作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为我们的 swift 代码添加可访问性 - 用于自动化目的最终目标是点击一个具有唯一标识符的按钮。
当前的实现看起来像:
var body: some View {
NavigationView {
ZStack {
VStack {
HStack{
Picker(selection: _ , label: Text("")) {
Image(systemName: "list.bullet").tag().accessibility(identifier: "list")
Image(systemName: "square.grid.3x2.fill").tag().accessibility(identifier: "grid")
}
.pickerStyle(SegmentedPickerStyle())
}
}
}
}
}
我相信当 .pickerStyle 被转换成分段控件,并且图像变成按钮时,xcode 会删除所有可访问性特征。应用程序的控制台输出如下所示:
SegmentedControl, 0x60000121e4c0, {{668.0, 90.0}, {150.0, 32.0}}
Button, 0x60000121e5a0, {{668.0, 90.0}, {74.0, 32.0}}, Selected
Button, 0x60000121e680, {{743.0, 90.0}, {75.0, 32.0}}
在其他方面,Image with .accessibility(identifier: "") 工作得很好,所以它必须与 pickerStyle 有关。
我也试过这个属性的可访问性:
.accessibility(hidden: false)
.accessibility(label: "")
.accessibility(value: "")
有谁知道如何解决这个问题?所以最后,调试器可以打印:
SegmentedControl, 0x60000121e4c0, {{668.0, 90.0}, {150.0, 32.0}}
Button, 0x60000121e5a0, {{668.0, 90.0}, {74.0, 32.0}}, identifier: 'list', Selected
Button, 0x60000121e680, {{743.0, 90.0}, {75.0, 32.0}}, identifier: 'grid'
最佳答案
带有辅助功能标签的解决方案
对于带有图像的分段选择器的可访问性标签,我遇到了同样的问题。这是我如何让它工作的(在可重用的 View 中):
enum Choice: CaseIterable, Hashable {
case one, two, three
}
struct MyPickerView: View {
@Binding var choice: Choice
static let choices: [Choice: String] = [
.one: "1.circle",
.two: "2.circle",
.three: "3.circle"
]
static let hints: [Choice: LocalizedStringKey] = [
.one: "One item",
.two: "Two items",
.three: "Three items"
]
var body: some View {
Picker(selection: $choice.animation(), label: Text("")) {
ForEach(Choice.allCases, id: \.self) { choice in
Image(systemName: Self.choices[choice]!)
.tag(choice)
// Needed for VoiceOver on unselected items
.accessibility(label: Text(Self.hints[choice]!))
}
}
.pickerStyle(SegmentedPickerStyle())
// Needed the first time VoiceOver is on the selected item
.accessibility(label: Text(Self.hints[self.choice]!))
}
}
两个 .accessibility
修饰符都是必需的,以便 VoiceOver 在所有情况下都说出辅助功能提示。然后需要有一个明确的 @State
或 @Binding
变量来保持对选择的引用。
关于swift - 分段选择器移除了可访问性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60894793/
我正在做一个项目,我的 android 在这个项目中作为一个网络服务器工作;输入带端口号的 IP 地址,打开 Web 界面,用户可以将文件上传到手机。我想在 Web 界面上显示一些图片,以便我们的界面
我是一名优秀的程序员,十分优秀!