0

我有一个从底部偏移的视图。它本质上是一个从底部出现的菜单。在向下拖动以将其关闭时,如果我碰巧用另一根手指触摸它,则视图会停留在该位置,并且当我放手时不会返回到 .zero 。这不是想要的行为。

struct View1: View {

@State var bottomState = CGSize.zero
@State var showCard = false
@State var show = false
var body: some View {
    
    ZStack {
                
    Text("PRESS ME")
            .offset(y:-200)
        .onTapGesture {
            self.showCard.toggle()
        }
    
    View2()
        .offset(x:0, y: showCard ? 360 : 1000)
        .offset(y: bottomState.height)
        .blur(radius: show ? 20 : 0)
        .gesture(
            DragGesture().onChanged { value in
                self.bottomState = value.translation
            } .onEnded({ value in
                self.bottomState = .zero
            })
        )
        
    } //Z
}

}

结构视图2:查看{

var body: some View {
    
    
    VStack {
        
        Text("Rene")
            .padding(.top, 50)
        
        
        Spacer()
    }.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
        .background(.gray)
        .ignoresSafeArea()
    
    
}

}

4

0 回答 0