Xcode 12 测试版 4
我有这个 ContentView 有两个不同的模式视图。我想用来sheet(isPresented: onDismiss: content:)显示第一个视图,当它关闭时,自动显示第二个视图。
struct ContentView: View {
@State var showFirst = false
@State var showSecond = false
var body: some View {
VStack(spacing: 20) {
Text("showFirst: \(showFirst.description)")
Text("showSecond: \(showSecond.description)")
Button("show") {
showFirst.toggle()
}
.sheet(isPresented: $showFirst) {
showSecond.toggle()
} content: {
FirstView(isPresented: $showFirst)
}
Text("")
.sheet(isPresented: $showSecond) {
SecondView(isPresented: $showSecond)
}
}
}
}
struct FirstView: View {
@Binding var isPresented: Bool
var body: some View {
VStack {
Button("close") {
isPresented …Run Code Online (Sandbox Code Playgroud)