實例方法
popover(is
popover(isPresented:attachmentAnchor:arrowEdge:content:)
當給定條件為真時顯示彈出框。
聲明
func popover<Content>(
isPresented: Binding<Bool>,
attachmentAnchor: PopoverAttachmentAnchor = .rect(.bounds),
arrowEdge: Edge = .top,
content: @escaping () -> Content
) -> some View where Content : View
參數
isPresented
與布爾值的綁定,該值確定是否顯示從修改器的
content
閉包返回的彈出框內容。attachmentAnchor
定義彈出框附著點的定位錨。默認值為
Anchor/Source/bounds
。arrowEdge
attachmentAnchor
的邊,用於定義 macOS 中彈出框箭頭的位置。默認值為Edge/top
。 iOS 忽略此參數。content
返回彈出框內容的閉包。
詳述
使用此方法顯示一個彈出框,其內容是您在綁定布爾變量為 true
時提供的 SwiftUI 視圖。在下麵的示例中,隻要用戶通過按下 “Show Popover” 按鈕切換 isShowingPopover
狀態變量,就會顯示一個彈出框:
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()
}
}
}
可用版本
iOS 13.0+, iPadOS 13.0+, macOS 10.15+, Mac Catalyst 13.0+
相關用法
- Swift Never popover(item:attachmentAnchor:arrowEdge:content:)用法及代碼示例
- Swift Never position(x:y:)用法及代碼示例
- Swift Never position(_:)用法及代碼示例
- Swift Never pageCommand(value:in:step:)用法及代碼示例
- Swift Never previewDisplayName(_:)用法及代碼示例
- Swift Never progressViewStyle(_:)用法及代碼示例
- Swift Never projectionEffect(_:)用法及代碼示例
- Swift Never padding(_:_:)用法及代碼示例
- Swift Never previewLayout(_:)用法及代碼示例
- Swift Never previewDevice(_:)用法及代碼示例
- Swift Never preferredColorScheme(_:)用法及代碼示例
- Swift Never prefersDefaultFocus(_:in:)用法及代碼示例
- Swift Never privacySensitive(_:)用法及代碼示例
- Swift Never previewInterfaceOrientation(_:)用法及代碼示例
- Swift Never padding(_:)用法及代碼示例
- Swift Never opacity(_:)用法及代碼示例
- Swift Never colorMultiply(_:)用法及代碼示例
- Swift Never accessibilityAction(action:label:)用法及代碼示例
- Swift Never alert(isPresented:error:actions:message:)用法及代碼示例
- Swift Never confirmationDialog(_:isPresented:titleVisibility:actions:)用法及代碼示例
- Swift Never flipsForRightToLeftLayoutDirection(_:)用法及代碼示例
- Swift Never luminanceToAlpha()用法及代碼示例
- Swift Never accessibilityAction(_:_:)用法及代碼示例
- Swift Never badge(_:)用法及代碼示例
- Swift Never buttonStyle(_:)用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Never popover(isPresented:attachmentAnchor:arrowEdge:content:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。