SwiftUI-Modal presentations

模态演示文稿

在单独的视图中呈现内容,以提供有重点的互动。

要提请注意一个重要的、范围狭窄的任务,您会显示一个模态演示文稿,如警报、弹出窗口、工作表或确认对话框。

在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
有条件地防止弹出窗口或工作表的交互式关闭。
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,544评论 6 501
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,430评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,764评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,193评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,216评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,182评论 1 299
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,063评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,917评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,329评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,543评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,722评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,425评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,019评论 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,671评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,825评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,729评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,614评论 2 353

推荐阅读更多精彩内容