同时用于一组文本的辅助功能标识符,以及每个文本的标识符

问题描述 投票:0回答:1

例如代码:

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”获取值

swift swiftui accessibility uiaccessibility
1个回答
0
投票

如果我理解正确,您应该在辅助功能标识符之前添加

.accessibilityElement(children: .contain)

HStack {
    Text("Hello")
        .accessibilityIdentifier("first_word")
    Text(" ")
    Text("World!")
        .accessibilityIdentifier("second_word")
}
.accessibilityElement(children: .contain)
.accessibilityIdentifier("phrase")

另请参阅

.contain
文档中的代码示例,这与您的情况类似。

© www.soinside.com 2019 - 2024. All rights reserved.