實例方法
popover(item:
popover(item:attachmentAnchor:arrowEdge:content:)
使用給定項目作為彈出框內容的數據源呈現彈出框。
聲明
func popover<Item, Content>(
item: Binding<Item?>,
attachmentAnchor: PopoverAttachmentAnchor = .rect(.bounds),
arrowEdge: Edge = .top,
content: @escaping (Item) -> Content
) -> some View where Item : Identifiable, Content : View
參數
item
綁定到彈出框的可選事實來源。當
item
不是nil
時,係統會將內容傳遞給修飾符的閉包。您使用此內容來填充您創建的係統向用戶顯示的彈出框的字段。如果item
更改,係統將關閉當前呈現的彈出框並使用相同的過程將其替換為新的彈出框。attachmentAnchor
定義彈出框附著點的定位錨。默認值為
Anchor/Source/bounds
。arrowEdge
attachmentAnchor
的邊,用於定義 macOS 中彈出框箭頭的位置。默認值為Edge/top
。 iOS 忽略此參數。content
返回彈出框內容的閉包。
詳述
當您需要顯示包含自定義數據源內容的彈出框時,請使用此方法。下麵的示例使用 PopoverModel
結構中的數據來填充彈出框向用戶顯示的 content
閉包中的視圖:
struct PopoverExample: View {
@State var popover: PopoverModel?
var body: some View {
Button("Show Popover") {
popover = PopoverModel(message: "Custom Message")
}
.popover(item: $popover) { detail in
Text("\(detail.message)")
.padding()
}
}
}
struct PopoverModel: Identifiable {
var id: String { message }
let message: String
}
可用版本
iOS 13.0+, iPadOS 13.0+, macOS 10.15+, Mac Catalyst 13.0+
相關用法
- Swift Optional popover(isPresented:attachmentAnchor:arrowEdge:content:)用法及代碼示例
- Swift Optional position(_:)用法及代碼示例
- Swift Optional position(x:y:)用法及代碼示例
- Swift Optional preferredColorScheme(_:)用法及代碼示例
- Swift Optional previewDevice(_:)用法及代碼示例
- Swift Optional pageCommand(value:in:step:)用法及代碼示例
- Swift Optional padding(_:_:)用法及代碼示例
- Swift Optional previewInterfaceOrientation(_:)用法及代碼示例
- Swift Optional padding(_:)用法及代碼示例
- Swift Optional projectionEffect(_:)用法及代碼示例
- Swift Optional privacySensitive(_:)用法及代碼示例
- Swift Optional prefersDefaultFocus(_:in:)用法及代碼示例
- Swift Optional previewLayout(_:)用法及代碼示例
- Swift Optional previewDisplayName(_:)用法及代碼示例
- Swift Optional progressViewStyle(_:)用法及代碼示例
- Swift Optional symbolVariant(_:)用法及代碼示例
- Swift Optional mask(alignment:_:)用法及代碼示例
- Swift Optional listSectionSeparatorTint(_:edges:)用法及代碼示例
- Swift Optional badge(_:)用法及代碼示例
- Swift Optional fullScreenCover(isPresented:onDismiss:content:)用法及代碼示例
- Swift Optional keyboardType(_:)用法及代碼示例
- Swift Optional clipShape(_:style:)用法及代碼示例
- Swift Optional background(_:ignoresSafeAreaEdges:)用法及代碼示例
- Swift Optional saturation(_:)用法及代碼示例
- Swift Optional focusSection()用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Optional popover(item:attachmentAnchor:arrowEdge:content:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。