SwiftUI 模态对话框

SwiftUI 模态对话框,第1张

import SwiftUI

struct ReplaceView: View {
    @State var isshow = false
    var body: some View {
        VStack{
            Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
                .onTapGesture {
                    self.isshow.toggle()
                }
        }.frame(width: 800, height: 600, alignment: .center)
            .sheet(isPresented: $isshow,
                   content: {TestView(isshow:self.$isshow)})
        
    }
}

struct TestView:View{
    @Binding var isshow:Bool
    var body:some View{
        VStack{
            Text("ddd").onTapGesture {
                self.isshow = false
            }
        }.frame(width: 400, height: 300, alignment: .center)
    }
}

struct ReplaceView_Previews: PreviewProvider {
    static var previews: some View {
        ReplaceView()
    }
}

这个在mac做了测试

单击文字,d出对话框

单击ddd,隐藏对话框。 

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/993617.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存