使用@Binding绑定包装关闭模态窗口


struct ContentView : View
{
@State var isPresented = false
var body: some View
{
PopView(show: $isPresented)
.sheet(isPresented: $isPresented, content:
{
Button(action:
{
self.isPresented.toggle()
}){
Text("Dismiss")
.font(.largeTitle)
}
})
}
}
struct PopView: View
{
@Binding var show : Bool
var body: some View
{
Button(action:
{
self.show.toggle()
}) {
Image(systemName: "person.crop.circle")
.font(.system(size: 32))
.frame(width: 64, height: 64)
.foregroundColor(.black)
.background(Color.white)
.cornerRadius(30)
.shadow(color: .pink, radius: 10, x: 0, y: 10)
}
}
}