例如代码:
HStack {
Text("Hello")
.accessibilityIdentifier("first_word")
Text(" ")
Text("World!")
.accessibilityIdentifier("second_word")
}
// Place, where I want to put "phrase_identifier",
// but it will override "first_word" and "second_word" identifiers
是否可以创建返回“Hello World!”的“phrase_identifier”,同时可以通过“first_word”=“Hello”、“second_word”=“World!”来获取文本寻址?
更新: 下面提出了下一个解决方案,但结果它创建了一组标识符,并且我无法通过“phrase_identifier”获取值
如果我理解正确,您应该在辅助功能标识符之前添加
.accessibilityElement(children: .contain)
。
HStack {
Text("Hello")
.accessibilityIdentifier("first_word")
Text(" ")
Text("World!")
.accessibilityIdentifier("second_word")
}
.accessibilityElement(children: .contain)
.accessibilityIdentifier("phrase")
.contain
文档中的代码示例,这与您的情况类似。