Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode 设置动画时隐藏视图,状态属性位于不同的结构中_Xcode_Model View Controller_View_State_Swiftui - Fatal编程技术网

Xcode 设置动画时隐藏视图,状态属性位于不同的结构中

Xcode 设置动画时隐藏视图,状态属性位于不同的结构中,xcode,model-view-controller,view,state,swiftui,Xcode,Model View Controller,View,State,Swiftui,我的视图中有一个矩形,当按下它时,它会展开,以便向用户显示更多细节 现在在底部,我必须显示其他内容。一旦用户按下矩形,它需要覆盖这些数据 正如您在我的图片上看到的,一旦我按下矩形,视图将展开,但文本(“CIAO”)仍然可见 我的想法是在用户按下矩形后使用@State将视图设置为hidden() 但问题是,我正在检测用户是否在另一个struct RectanglePersonal中按下矩形(使用状态isExpanded) 如何从struct RectanglePersonal中检测@isExpa

我的视图中有一个矩形,当按下它时,它会展开,以便向用户显示更多细节

现在在底部,我必须显示其他内容。一旦用户按下矩形,它需要覆盖这些数据

正如您在我的图片上看到的,一旦我按下矩形,视图将展开,但文本(“CIAO”)仍然可见

我的想法是在用户按下矩形后使用@State将视图设置为hidden() 但问题是,我正在检测用户是否在另一个struct RectanglePersonal中按下矩形(使用状态isExpanded)


如何从struct RectanglePersonal中检测@isExpanded的值?并从我的视图中读取详细信息ViewNew?要隐藏文本“CIAO”

请使用@Binding;)您是否检查过图纸(也称为模态视图)在SwiftUI中的工作方式?不要试图重新创造它。。。
struct DetailViewNew: View {
    var dm : DataManager
    let general: GenAirportModel

    var body: some View {
        VStack {

            ZStack {
                GeometryReader { geo in

                 VStack(alignment:.leading){
                    self.airport
                        .padding(.horizontal)
                        .offset(y: geo.size.height/6.3)
                    RectanglePersonal(general: self.general)


                 }
                 .frame(width: geo.size.width, height: geo.size.height/2.5)
                 .background(LinearGradient(gradient: Gradient(colors: [Color("BlueW"), Color("DARK")]), startPoint: .topLeading, endPoint: .bottomTrailing).shadow(radius: 2))
                 .edgesIgnoringSafeArea(.all)

                Spacer()


                }
                Text("CIAO")

            }
            Spacer()
        }

    }

struct RectanglePersonal: View {
    let general: GenAirportModel
    @State private var isExpanded = false

    var body : some View {
        GeometryReader { g in
            ZStack(alignment:.leading) {
                Rectangle()
                    .foregroundColor(.clear)
                    .background(LinearGradient(gradient: Gradient(colors: [Color("BlueW"), Color("DARK")]), startPoint: .topLeading, endPoint: .bottomTrailing))
//                    .blur(radius: 20)

                    .cornerRadius(20)
//                    .foregroundColor(Color("BlueW"))

                    .shadow(color: .white, radius: 10)
                    .padding(.horizontal,5)
                    .frame(width: g.size.width,
                           height: self.isExpanded ? g.size.height*2 : g.size.height/1.3)
                    .offset(y: self.isExpanded ? g.size.height : g.size.height/2.5)
                    .animation(.easeInOut(duration: 0.5))
                VStack(alignment:.leading) {
                    Text("METAR:")
                        .bold()
                    Text(self.general.metarData.raw_text)
                        .lineLimit(self.isExpanded ? nil : 2)
                    .animation(.easeInOut(duration: 0.5))
                    Text("TAF:")
                        .bold()
                    Text(self.general.tafData.raw_text)
                        .lineLimit(self.isExpanded ? nil : 2)
                    .animation(.easeInOut(duration: 0.5))
                }
                    .padding(.horizontal)
                    .offset(y: self.isExpanded ? g.size.height : g.size.height/2.5)
                .animation(.easeInOut(duration: 0.5))
            }.padding()
                .onTapGesture {
                    self.isExpanded.toggle()
            }
        }
    }
}