我有一个自定义
TextField
结构,我使用 .accessibilityElement(children: .combine)
使 Siri 读出 Text
+ TextField
值,但“她”删除了 textField 的 textField 可访问性特征,其中显示“双击进行编辑”。除了设置我自己的提示之外,我真的找不到一种方法来读取,这看起来有点糟糕。这个问题有更好的解决办法吗?
struct CustomTextField<F: ParseableFormatStyle>: View where F.FormatOutput == String {
let title: String
var value: Binding<F.FormatInput?>
let format: F
var body: some View {
VStack(spacing: 6) {
Text(title)
.frame(maxWidth: .infinity, alignment: .leading)
TextField("", value: value, format: format)
.autocorrectionDisabled()
}
.accessibilityElement(children: .combine)
// .accessibilityHint("Double tap to edit") // Is this the only way?
}
}
看看吧
.accessibilityRepresentation {
// Custom accessibility representation of your view that VoiceOver (and other technologies) will use.
}
https://developer.apple.com/documentation/swiftui/view/accessibilityrepresentation(表示:)
或
.accessibilityChildren {
// Custom accessibility representation of your view that VoiceOver (and other technologies) will use.
}
https://developer.apple.com/documentation/swiftui/view/accessibilitychildren(儿童:)
两个修饰符的差异非常小。
对于您使用文本字段的确切用例,我使用了
.accessibilityChildren
。不过,这取决于您的实际设置。
这里有一篇文章,其中简要提到了差异:https://swiftwithmajid.com/2022/05/25/the-power-of-accessibilityChildren-view-modifier-in-swiftui/