模态演示文稿
在单独的视图中呈现内容,以提供有重点的互动。
要提请注意一个重要的、范围狭窄的任务,您会显示一个模态演示文稿,如警报、弹出窗口、工作表或确认对话框。
在SwiftUI中,您可以使用视图修饰符创建模态演示文稿,该修饰符定义演示文稿的外观以及SwiftUI呈现演示文稿的条件。SwiftUI检测条件何时发生变化,并为您做演示文稿。由于您为启动演示文稿的条件提供了Binding
,因此当用户关闭演示文稿时,SwiftUI可以重置底层值。
显示工作表、封面或弹出窗口
func sheet<Content>(isPresented: Binding<Bool>, onDismiss: (() -> Void)?, content: () -> Content) -> some View
当您提供的布尔值绑定为真时,显示工作表。
func sheet<Item, Content>(item: Binding<Item?>, onDismiss: (() -> Void)?, content: (Item) -> Content) -> some View
使用给定项目作为工作表内容的数据源呈现工作表。
func fullScreenCover<Content>(isPresented: Binding<Bool>, onDismiss: (() -> Void)?, content: () -> Content) -> some View
显示模态视图,当绑定到您提供的布尔值时,尽可能多地覆盖屏幕。
func fullScreenCover<Item, Content>(item: Binding<Item?>, onDismiss: (() -> Void)?, content: (Item) -> Content) -> some View
使用您作为工作表内容的数据源提供的绑定,显示尽可能多地覆盖屏幕的模态视图。
func popover<Content>(isPresented: Binding<Bool>, attachmentAnchor: PopoverAttachmentAnchor, arrowEdge: Edge, content: () -> Content) -> some View
当给定条件为真时,显示一个弹出窗口。
func popover<Item, Content>(item: Binding<Item?>, attachmentAnchor: PopoverAttachmentAnchor, arrowEdge: Edge, content: (Item) -> Content) -> some View
使用给定项目作为弹出窗口内容的数据源来显示弹出窗口。
enum PopoverAttachmentAnchor
弹出窗口的附件锚。
根据大小类调整演示文稿
func presentationCompactAdaptation(horizontal: PresentationAdaptation, vertical: PresentationAdaptation) -> some View
指定如何将演示文稿调整为水平和垂直紧凑的大小类。
func presentationCompactAdaptation(PresentationAdaptation) -> some View
指定如何将演示文稿调整为紧凑大小的类。
struct PresentationAdaptation
将演示文稿调整到不同大小的班级的策略。
配置工作表的高度
func presentationDetents(Set<PresentationDetent>) -> some View
设置封闭表的可用支架。
func presentationDetents(Set<PresentationDetent>, selection: Binding<PresentationDetent>) -> some View
设置封闭表的可用表示式,让您对当前选定的表示进行编程控制。
func presentationContentInteraction(PresentationContentInteraction) -> some View
配置演示文稿上滑动手势的行为。
func presentationDragIndicator(Visibility) -> some View
在工作表顶部设置拖动指示器的可见性。
struct PresentationDetent
一种代表床单自然休息的高度的类型。
protocol CustomPresentationDetent
计算高度的自定义detent的定义。
struct PresentationContentInteraction
一种可用于影响演示文稿对轻扫手势的反应的行为。
造型及其背景
func presentationCornerRadius(CGFloat?) -> some View
要求演示文稿具有特定的角半径。
func presentationBackground() -> some View
将封闭表的演示背景设置为当前背景样式。
func presentationBackground<S>(S) -> some View
使用形状样式设置封闭表的演示文稿背景。
func presentationBackground<V>(alignment: Alignment, content: () -> V) -> some View
将封闭表的演示背景设置为自定义视图。
func presentationBackgroundInteraction(PresentationBackgroundInteraction) -> some View
控制人们是否可以与演示文稿背后的视图进行交互。
struct PresentationBackgroundInteraction
演示文稿背后视图可用的互动类型。
呈现提醒
func alert<S, A>(S, isPresented: Binding<Bool>, actions: () -> A) -> some View
当给定条件为真时,使用字符串变量作为标题显示警报。
func alert<A>(Text, isPresented: Binding<Bool>, actions: () -> A) -> some View
当给定条件为真时,使用标题的文本视图显示警报。
func alert<A>(LocalizedStringKey, isPresented: Binding<Bool>, actions: () -> A) -> some View
当给定条件为真时,使用标题的本地化字符串键显示警报。
func alert<A, T>(Text, isPresented: Binding<Bool>, presenting: T?, actions: (T) -> A) -> some View
使用给定数据显示警报,以生成警报的内容和文本视图作为标题。
func alert<A, T>(LocalizedStringKey, isPresented: Binding<Bool>, presenting: T?, actions: (T) -> A) -> some View
使用给定数据显示警报,以生成警报的内容和标题的本地化字符串键。
func alert<S, A, T>(S, isPresented: Binding<Bool>, presenting: T?, actions: (T) -> A) -> some View
使用给定数据显示警报,以生成警报的内容和字符串变量作为标题。
func alert<E, A>(isPresented: Binding<Bool>, error: E?, actions: () -> A) -> some View
当存在错误时显示警报。
展示带有消息的警报
func alert<S, A, M>(S, isPresented: Binding<Bool>, actions: () -> A, message: () -> M) -> some View
当给定条件为真时,使用字符串变量作为标题时,显示带有消息的警报。
func alert<A, M>(LocalizedStringKey, isPresented: Binding<Bool>, actions: () -> A, message: () -> M) -> some View
当给定条件为真时,使用标题的本地化字符串键显示带有消息的警报。
func alert<A, M>(Text, isPresented: Binding<Bool>, actions: () -> A, message: () -> M) -> some View
当给定条件为真时,使用文本视图作为标题显示带有消息的警报。
func alert<A, M, T>(LocalizedStringKey, isPresented: Binding<Bool>, presenting: T?, actions: (T) -> A, message: (T) -> M) -> some View
呈现带有消息的警报,使用给定数据生成警报的内容和标题的本地化字符串键。
func alert<A, M, T>(Text, isPresented: Binding<Bool>, presenting: T?, actions: (T) -> A, message: (T) -> M) -> some View
使用给定数据显示带有消息的警报,以生成警报的内容和标题的文本视图。
func alert<S, A, M, T>(S, isPresented: Binding<Bool>, presenting: T?, actions: (T) -> A, message: (T) -> M) -> some View
呈现带有消息的警报,使用给定数据生成警报的内容和字符串变量作为标题。
func alert<E, A, M>(isPresented: Binding<Bool>, error: E?, actions: (E) -> A, message: (E) -> M) -> some View
当存在错误时,显示带有消息的警报。
获取行动确认
func confirmationDialog<S, A>(S, isPresented: Binding<Bool>, titleVisibility: Visibility, actions: () -> A) -> some View
当给定条件为真时,使用字符串变量作为标题显示确认对话框。
func confirmationDialog<A>(Text, isPresented: Binding<Bool>, titleVisibility: Visibility, actions: () -> A) -> some View
当给定条件为真时,使用标题的文本视图显示确认对话框。
func confirmationDialog<A>(LocalizedStringKey, isPresented: Binding<Bool>, titleVisibility: Visibility, actions: () -> A) -> some View
当给定条件为真时,使用标题的本地化字符串键显示确认对话框。
func confirmationDialog<A, T>(Text, isPresented: Binding<Bool>, titleVisibility: Visibility, presenting: T?, actions: (T) -> A) -> some View
呈现一个确认对话框,使用数据生成对话框的内容和标题的文本视图。
func confirmationDialog<A, T>(LocalizedStringKey, isPresented: Binding<Bool>, titleVisibility: Visibility, presenting: T?, actions: (T) -> A) -> some View
呈现一个确认对话框,使用数据生成对话框的内容,并为标题显示本地化字符串键。
func confirmationDialog<S, A, T>(S, isPresented: Binding<Bool>, titleVisibility: Visibility, presenting: T?, actions: (T) -> A) -> some View
呈现一个确认对话框,使用数据生成对话框的内容和标题的字符串变量。
显示带有消息的确认对话框
func confirmationDialog<S, A, M>(S, isPresented: Binding<Bool>, titleVisibility: Visibility, actions: () -> A, message: () -> M) -> some View
当给定条件为真时,使用标题的字符串变量显示带有消息的确认对话框。
func confirmationDialog<A, M>(LocalizedStringKey, isPresented: Binding<Bool>, titleVisibility: Visibility, actions: () -> A, message: () -> M) -> some View
当给定条件为真时,使用标题的本地化字符串键显示带有消息的确认对话框。
func confirmationDialog<A, M>(Text, isPresented: Binding<Bool>, titleVisibility: Visibility, actions: () -> A, message: () -> M) -> some View
当给定条件为真时,使用标题的文本视图显示带有消息的确认对话框。
func confirmationDialog<A, M, T>(Text, isPresented: Binding<Bool>, titleVisibility: Visibility, presenting: T?, actions: (T) -> A, message: (T) -> M) -> some View
呈现一个确认对话框,其中包含一条消息,使用数据生成对话框的内容和消息的文本视图。
func confirmationDialog<S, A, M, T>(S, isPresented: Binding<Bool>, titleVisibility: Visibility, presenting: T?, actions: (T) -> A, message: (T) -> M) -> some View
呈现一个确认对话框,其中包含一条消息,使用数据生成对话框的内容,并为标题显示字符串变量。
func confirmationDialog<A, M, T>(LocalizedStringKey, isPresented: Binding<Bool>, titleVisibility: Visibility, presenting: T?, actions: (T) -> A, message: (T) -> M) -> some View
呈现一个确认对话框,其中包含一条消息,使用数据生成对话框的内容,并为标题显示本地化字符串键。
呈现文件系统对话框
func fileExporter<D>(isPresented: Binding<Bool>, document: D?, contentType: UTType, defaultFilename: String?, onCompletion: (Result<URL, Error>) -> Void) -> some View
呈现一个系统接口,用于将存储在值类型(如结构)中的文档导出到磁盘上的文件。
func fileExporter<D>(isPresented: Binding<Bool>, document: D?, contentType: UTType, defaultFilename: String?, onCompletion: (Result<URL, Error>) -> Void) -> some View
呈现一个系统接口,用于将存储在引用类型(如类)中的文档导出到磁盘上的文件。
func fileExporter<C>(isPresented: Binding<Bool>, documents: C, contentType: UTType, onCompletion: (Result<[URL], Error>) -> Void) -> some View
呈现一个系统接口,用于将值类型文档的集合导出到磁盘上的文件。
func fileExporter<C>(isPresented: Binding<Bool>, documents: C, contentType: UTType, onCompletion: (Result<[URL], Error>) -> Void) -> some View
呈现一个系统接口,用于将参考类型文档集合导出到磁盘上的文件。
func fileImporter(isPresented: Binding<Bool>, allowedContentTypes: [UTType], allowsMultipleSelection: Bool, onCompletion: (Result<[URL], Error>) -> Void) -> some View
呈现一个系统界面,允许用户导入多个文件。
func fileImporter(isPresented: Binding<Bool>, allowedContentTypes: [UTType], onCompletion: (Result<URL, Error>) -> Void) -> some View
呈现一个系统界面,允许用户导入现有文件。
func fileMover(isPresented: Binding<Bool>, file: URL?, onCompletion: (Result<URL, Error>) -> Void) -> some View
呈现一个系统界面,允许用户将现有文件移动到新位置。
func fileMover<C>(isPresented: Binding<Bool>, files: C, onCompletion: (Result<[URL], Error>) -> Void) -> some View
提供了一个系统界面,允许用户将现有文件的集合移动到新位置。
驳回演示文稿
var isPresented: Bool
一个布尔值,指示当前是否显示与此环境关联的视图。
var dismiss: DismissAction
驳回当前演示文稿的行动。
struct DismissAction
驳回演示文稿的诉讼。
func interactiveDismissDisabled(Bool) -> some View
有条件地防止弹出窗口或工作表的交互式关闭。