SwiftUI在视图中添加-y偏移量,但将视图延伸至底部

时间:2019-09-15 20:06:12

标签: swiftui

我的代码中有2个视图,分别是VStack和自定义视图。

我正在向-75的第二个视图添加偏移量,以将其移动到第一个视图的顶部。

这是我当前的代码:

Group {
       VStack {
           //First View
           VStack {
               Image("LogoCrest")

                NavigationLink(destination: LocationSearch()) {
                    Text("Find a location")
                    .foregroundColor(Color.white)
                    .bold()
                    .padding()
                }
                .frame(minWidth: 0, maxWidth: .infinity, alignment: Alignment.center)
                .background(Color(red: 81 / 255, green: 175 / 255, blue: 67 / 255))
                .cornerRadius(7)
                .padding()

           }
           .padding(.top, 75)
           .padding(.bottom, 75)
           .frame(minWidth: 0, maxWidth: .infinity, alignment: Alignment.center)
           .background(Color(red: 49 / 255, green: 49 / 255, blue: 49 / 255))

           //Second view
           CircuitList(Circuits: Circuits)
            .offset(y: -75)
           .padding()
       }
     }
    .background(Color(red: 232 / 255, green: 232 / 255, blue: 232 / 255))
    .edgesIgnoringSafeArea(.top)

如何增加第二个视图的高度,使其始终位于底部(我想要的额外高度,请参见下图中的黑线)?

My view

1 个答案:

答案 0 :(得分:2)

我找到了答案。 由于我在视图中添加了y:-75偏移量,因此我也必须添加y:-75填充。

CircuitList(Circuits: Circuits)
    .offset(y: -75)
    .padding()
    .padding(.bottom, -75)
相关问题