美文网首页
SwiftUI-Presentations

SwiftUI-Presentations

作者: xiaofu666 | 来源:发表于2023-02-28 10:21 被阅读0次

PresentationAdaptation

将这种类型的值与presentationAdaptation(_:)presentationAdaptation(horizontal:vertical:)修饰符一起使用。

获取适应策略

static var automatic: PresentationAdaptation
使用默认的演示文稿改编。
static var none: PresentationAdaptation
如果可能的话,不要适应尺寸类。
static var fullScreenCover: PresentationAdaptation
在适应尺寸类时,更喜欢全屏封面外观。
static var popover: PresentationAdaptation
在适应大小类时,更喜欢弹出窗口外观。
static var sheet: PresentationAdaptation
在适应大小类时,更喜欢工作表外观。

根据大小类调整演示文稿

func presentationCompactAdaptation(horizontal: PresentationAdaptation, vertical: PresentationAdaptation) -> some View
指定如何将演示文稿调整为水平和垂直紧凑的大小类。
func presentationCompactAdaptation(PresentationAdaptation) -> some View
指定如何将演示文稿调整为紧凑大小的类。

PresentationDetent

一种代表自然高度的类型。

获取内置支架

static let large: PresentationDetent
系统在全高处安装一张床单。
static let medium: PresentationDetent
系统用于大约屏幕高度的一半,并且在紧凑的高度上处于非活动状态。
创建自定义表示
static func custom<D>(D.Type) -> PresentationDetent
计算高度的自定义detent。
static func fraction(CGFloat) -> PresentationDetent
具有指定分数高度的自定义指示器。
static func height(CGFloat) -> PresentationDetent
具有指定高度的自定义指示器。
struct Context
您用于计算演示文稿高度的信息。

比较耳动

static func == (PresentationDetent, PresentationDetent) -> Bool
指示两个演示否数相等。
static func != (Self, Self) -> Bool
指示两个演示否定点是否不相等。
func hash(into: inout Hasher)
通过将演示文稿的基本组件传递到给定的哈希函数中,将它们散列起来。
var hashValue: Int
演示文稿的哈希值。

配置工作表的高度

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
在工作表顶部设置拖动指示器的可见性。
protocol CustomPresentationDetent
计算高度的自定义detent的定义。
struct PresentationContentInteraction
一种可用于影响演示文稿对轻扫手势的反应的行为。

PresentationContentInteraction

一种可用于影响演示文稿对轻扫手势的反应的行为。

将这种类型的值与presentationInteraction(_:)修饰符一起使用。

获取互动行为

static var automatic: PresentationContentInteraction
演示文稿的默认滑动行为。
static var resizes: PresentationContentInteraction
轻扫时优先调整演示文稿大小的行为,而不是滚动演示文稿的内容。
static var scrolls: PresentationContentInteraction
一种在滑动时优先滚动演示文稿内容而不是调整演示文稿大小的行为。
static func == (PresentationContentInteraction, PresentationContentInteraction) -> Bool
返回一个布尔值,指示两个值是否相等。

配置工作表的高度

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的定义。

PresentationBackgroundInteraction

演示文稿背后视图可用的互动类型。

将这种类型的值与presentationInteraction(_:)修饰符一起使用。

获取互动类型

static var automatic: PresentationBackgroundInteraction
演示文稿的默认背景互动。
static var disabled: PresentationBackgroundInteraction
人们无法与演示文稿背后的视图进行交互。
static var enabled: PresentationBackgroundInteraction
人们可以与演示文稿背后的视图进行交互。
static func enabled(upThrough: PresentationDetent) -> PresentationBackgroundInteraction
人们可以通过指定的指示与演示文稿背后的视图进行交互。
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
控制人们是否可以与演示文稿背后的视图进行交互。

DismissAction

使用dismiss环境值获取给定Environment的此结构实例。然后调用实例执行解雇。您直接调用实例,因为它定义了Swift在调用实例时调用的callFunction()方法。
你可以使用以下操作:
关闭模态演示文稿,如工作表或弹出窗口。
Navigation弹出当前视图。
关闭您使用WindowWindow创建的窗口
行动的具体行为取决于你从哪里调用它。例如,您可以在充当工作表的视图中创建一个按钮,调用Dismiss

private struct SheetContents: View {
    @Environment(\.dismiss) private var dismiss

    var body: some View {
        Button("Done") {
            dismiss()
        }
    }
}

当您显示工作表内容视图时,有人可以通过点击或单击工作表的按钮来关闭工作表:

private struct DetailView: View {
    @State private var isSheetPresented = false

    var body: some View {
        Button("Show Sheet") {
            isSheetPresented = true
        }
        .sheet(isPresented: $isSheetPresented) {
            SheetContents()
        }
    }
}

确保您在适当的环境中定义了操作。例如,不要重新组织上面示例中的Detail,使其创建dismiss属性,并从sheet(item:onDismiss:content:)视图修饰符content闭包调用它:

private struct DetailView: View {
    @State private var isSheetPresented = false
    @Environment(\.dismiss) private var dismiss // Applies to DetailView.

    var body: some View {
        Button("Show Sheet") {
            isSheetPresented = true
        }
        .sheet(isPresented: $isSheetPresented) {
            Button("Done") {
                dismiss() // Fails to dismiss the sheet.
            }
        }
    }
}

如果您这样做,工作表将无法关闭,因为该操作适用于您声明它的环境,即详细信息视图,而不是工作表。事实上,在macOS和iPadOS中,如果DetailView是窗口的根视图,则关闭操作会关闭窗口。

驳回操作对当前未显示的视图没有影响。如果您需要查询SwiftUI当前是否呈现视图,请阅读 isPresented 环境值。

呼吁采取行动

func callAsFunction()
如果当前显示视图,则将其关闭。

驳回演示文稿

var isPresented: Bool
一个布尔值,指示当前是否显示与此环境关联的视图。
var dismiss: DismissAction
驳回当前演示文稿的行动。
func interactiveDismissDisabled(Bool) -> some View
有条件地防止弹出窗口或工作表的交互式关闭。

相关文章

网友评论

      本文标题:SwiftUI-Presentations

      本文链接:https://www.haomeiwen.com/subject/nqyhldtx.html