目前的Modal全屏SwiftUI [英] Present Modal fullscreem SwiftUI

查看:569
本文介绍了目前的Modal全屏SwiftUI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何呈现一个模式,该模式会占用全屏屏幕,并且不能通过向下滑动来消除?目前,我正在使用.sheet来呈现可忽略的模态.

how can i present a modal that will take up the fullscreen and can't be dismissed by swiping it down? Currently I am using .sheet on a view to present a modal that is dismissible.

我还没有注意到Xcode中的任何beta版本更改都会改变这种行为.

I haven't noticed any beta changes in Xcode that changes this behavior.

任何帮助将不胜感激:)

Any help would be appreciated :)

推荐答案

SwiftUI 1.0

我不确定这是否符合您的要求,但是可以使用ZStack和状态变量来控制其隐藏/显示来创建自己的模态屏幕.

SwiftUI 1.0

I'm not sure if this what you'd want to go with but it's possible to create your own modal screen by using the ZStack and a state variable to control the hiding/showing of it.

struct CustomModalPopups: View {
    @State private var showingModal = false

    var body: some View {
        ZStack {
            VStack(spacing: 20) {
                Text("Custom Popup").font(.largeTitle)

                Text("Introduction").font(.title).foregroundColor(.gray)

                Text("You can create your own modal popup with the use of a ZStack and a State variable.")
                    .frame(maxWidth: .infinity)
                    .padding().font(.title).layoutPriority(1)
                    .background(Color.orange).foregroundColor(Color.white)

                Button(action: {
                    self.showingModal = true
                }) {
                    Text("Show popup")
                }
                Spacer()
            }

            // The Custom Popup is on top of the screen
            if $showingModal.wrappedValue {
                // But it will not show unless this variable is true
                ZStack {
                    Color.black.opacity(0.4)
                        .edgesIgnoringSafeArea(.vertical)
                    // This VStack is the popup
                    VStack(spacing: 20) {
                        Text("Popup")
                            .bold().padding()
                            .frame(maxWidth: .infinity)
                            .background(Color.orange)
                            .foregroundColor(Color.white)
                        Spacer()
                        Button(action: {
                            self.showingModal = false
                        }) {
                            Text("Close")
                        }.padding()
                    }
                    .frame(width: 300, height: 200)
                    .background(Color.white)
                    .cornerRadius(20).shadow(radius: 20)
                }
            }
        }
    }
}

示例

(摘自"SwiftUI视图"书) 因此,这里的弹出窗口很小,但是您可以使用该VStack上的frame修改器调整尺寸以使其全屏显示.

Example

(Excerpt from "SwiftUI Views" book) So here, your popup is small, but you can adjust the dimensions to make it fullscreen with the frame modifier that is on that VStack.

这篇关于目前的Modal全屏SwiftUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆