如何在SwiftUI中以模式方式推送下一个屏幕以使其满载 [英] How to Modally push next Screen to be full in SwiftUI
问题描述
我该如何推送下一个SwiftUI视图,但将其显示在全屏上而又不拖延Xcode 10模式演示文稿之类的功能.
how can I push a next SwiftUI View but present it over the full screen without swiping down feature like the Xcode 10 modal presentation.
我当前的实现方式,但并没有推动全屏显示(向下拖动并在顶部显示空白):
My current implementation, but it's not pushing onto the fullscreen (dragging down enabled and the gap at the top):
btn
.presentation(
!showModal.value ?
nil :
Popover(content: destination, dismissHandler: onTrigger ?? {})
)
推荐答案
我认为目前唯一的方法是使用 overlay()
或 ZStack
.使用 overlay()
时似乎无法正常工作,但使用 ZStack
I think the only way to do this at the moment is to use overlay()
or a ZStack
. I can't seem to get a transition working when using overlay()
but I can when using a ZStack
请确保您的模式视图使用 List
之类的内容或使用 Spacer()
填充屏幕,否则您仍将看到其后的其他视图
Just make sure your modal view fills the screen with something like a List
or using Spacer()
otherwise you will still see the other view behind it
struct ContentView: View {
@State var showModal = false
let transition = AnyTransition.move(edge: .bottom)
var body: some View {
ZStack {
VStack {
Button(action: {
withAnimation {
self.showModal = true
}
}) {
Text("Show Modal")
}
}
if self.showModal {
ModalView()
.background(Color.white)
.transition(transition)
}
}
}
}
这篇关于如何在SwiftUI中以模式方式推送下一个屏幕以使其满载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!