Instance Method インスタンスメソッド

popover(isPresented:attachmentAnchor:arrowEdge:content:)

Presents a popover when a given condition is true. ポップオーバーを提示します、与えられた条件がtrueの時に。

Declaration 宣言

func popover<Content>(isPresented: Binding<Bool>, attachmentAnchor: PopoverAttachmentAnchor = .rect(.bounds), arrowEdge: Edge = .top, content: @escaping () -> Content) -> some View where Content : View

Parameters パラメータ

isPresented

A binding to a Boolean value that determines whether to present the popover content that you return from the modifier’s content closure.

attachmentAnchor

The positioning anchor that defines the attachment point of the popover. The default is bounds.

arrowEdge

The edge of the attachmentAnchor that defines the location of the popover’s arrow in macOS. The default is Edge.top. iOS ignores this parameter.

content

A closure returning the content of the popover. ポップオーバーの内容を返しているクロージャ。

Discussion 議論

Use this method to show a popover whose contents are a SwiftUI view that you provide when a bound Boolean variable is true. In the example below, a popover displays whenever the user toggles the isShowingPopover state variable by pressing the “Show Popover” button:


struct PopoverExample: View {
    @State private var isShowingPopover = false


    var body: some View {
        Button("Show Popover") {
            self.isShowingPopover = true
        }
        .popover(isPresented: $isShowingPopover) {
            Text("Popover Content")
                .padding()
        }
    }
}

A screenshot showing a popover that says Popover Content hovering