如何根据SwiftUI中另一个视图的变量显示视图(在ContentView中)?

如何根据SwiftUI中另一个视图的变量显示视图(在ContentView中)?,view,binding,swiftui,mapbox,View,Binding,Swiftui,Mapbox,基本上,在我的ContentView中,当绑定variableName(不是ContentView中的variableName,而是MapView类中的variableName)为true时,我尝试创建一个CreateItemButton()。因此……ContentView的伪代码如下所示: struct ContentView: View { @State private var variableName: Bool = false var body: some View {

基本上,在我的ContentView中,当绑定variableName(不是ContentView中的variableName,而是MapView类中的variableName)为true时,我尝试创建一个CreateItemButton()。因此……ContentView的伪代码如下所示:

struct ContentView: View {
    @State private var variableName: Bool = false
    var body: some View {
        VStack {
            ZStack {
                MapView(variableName: $variableName)
                //Display the CreateEventButton() view here if $variableName is true.
            }
        }
    }
}
我希望有一些函数可以在MapView()视图上调用,以选择性地显示CreateEventButton()视图,但我发现最接近我需要的是.sheet(isPresented:$variableName)函数……我需要视图直接显示在地图的顶部,而不是在视图上拉一个新的工作表。让我知道,如果我可以添加任何东西,以帮助它更清楚

在这里

ZStack {
    MapView(variableName: $variableName)
    if variableName {
         CreateEventButton()
    }
}