jsb*_*eJS 3 iphone xcode modalviewcontroller ios swiftui
我怎样才能呈现一个将占据全屏并且不能通过向下滑动来消除的模式?目前我正在使用.sheet一个视图来呈现一个可关闭的模式。
我没有注意到 Xcode 中的任何测试版更改会改变这种行为。
任何帮助,将不胜感激 :)
Mar*_*ens 15
我不确定这是否是您想要的,但是可以通过使用 ZStack 和状态变量来控制它的隐藏/显示来创建自己的模态屏幕。
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)
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
(摘自“SwiftUI Views”一书)
所以在这里,您的弹出窗口很小,但您可以使用该 VStack 上的帧修改器调整尺寸以使其全屏显示。
| 归档时间: |
|
| 查看次数: |
5668 次 |
| 最近记录: |