首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >当前模式全屏SwiftUI

当前模式全屏SwiftUI
EN

Stack Overflow用户
提问于 2019-09-20 14:50:38
回答 1查看 5.9K关注 0票数 3

我如何才能呈现一个占据全屏的模式,并且不能通过向下滑动它来关闭它?目前,我在一个视图上使用.sheet来呈现一个可忽略的模式。

我没有注意到Xcode中有任何beta版本的改变改变了这个行为。

如有任何帮助,我们将不胜感激:)

EN

回答 1

Stack Overflow用户

发布于 2019-09-21 07:21:18

SwiftUI 1.0

我不确定这是否是您想要的,但是可以使用ZStack和一个状态变量来控制隐藏/显示,从而创建您自己的模式屏幕。

代码

代码语言:javascript
运行
复制
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 Views“一书)

所以在这里,你的弹出窗口很小,但你可以调整尺寸,让它通过VStack上的边框修饰符全屏显示。

票数 16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58023147

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档