Type Property 型プロパティ

contain

Any child accessibility elements become children of the new accessibility element.

Declaration 宣言

static let contain: AccessibilityChildBehavior

Discussion 議論

Use this behavior when you want a view to be an accessibility container. An accessibility container groups child accessibility elements which improves navigation. For example, all children of an accessibility container are navigated in order before navigating through the next accessibility container.


var body: some View {
    ScrollView {
        VStack {
            HStack {
                ForEach(users) { user in
                    UserCell(user)
                }
            }
            .accessibilityElement(children: .contain)
            .accessibilityLabel("Users")


            VStack {
                ForEach(messages) { message in
                    MessageCell(message)
                }
            }
            .accessibilityElement(children: .contain)
            .accessibilityLabel("Messages")
        }
    }
}

A new accessibility element is created when:

  • The view contains multiple or zero accessibility elements

  • The view contains a single accessibility element with no children