代码之家  ›  专栏  ›  技术社区  ›  Alex

如何将底部抽屉固定在屏幕底部?

  •  1
  • Alex  · 技术社区  · 1 年前

    下面是我在SwiftUI中创建视图的代码。我想把我最下面的抽屉连接到屏幕底部。

    struct BottomDrowerView: View {
        @State private var offset: CGFloat = 100
        var body: some View {
            GeometryReader { proxy in
                VStack{
                    
                }
            }
                .background(Color.red)
                .offset(y: offset)
                .gesture(
                    DragGesture()
                        .onChanged{ value in
                            let startLocation = value.startLocation
                            offset = startLocation.y + value.translation.height
                        }
                )
            }
        }
    

    enter image description here

    我试过了,

    .frame(maxHeight: .infinity, alignment: .bottom)

    但它不起作用。

    0 回复  |  直到 1 年前