0

I found the height was wrong when I'm dragging,how can i fix it?

The height in the tabview will be subtracted from the safe height when dragging.

work with tabview with background

work with tabview without background

work with backgroun without tabview

struct TabViewTest: View {
    @State var offset: CGFloat = 0
    @State var startY: CGFloat = 0
    
    var body: some View {
        ZStack(alignment: .top) {
            VStack {
                
                  // work without tabview
//                GeometryReader { proxy in
//                    ZStack {
//                        Color.green
//                            .frame(height: 100)
//                        Text("row height:\(proxy.size.height)")
//                    }
//                }
                // work with tabview without background
//                TabView {
//                    ForEach(0..<5) { i in
//                        GeometryReader { proxy in
//                            Text("row\(i) height:\(proxy.size.height)")
//                        }
//                    }
//                }

                // work with tabview
                TabView {
                    ForEach(0..<5) { i in
                        GeometryReader { proxy in
                            ZStack {
                                Color.green
                                    .frame(height: 100)
                                Text("row\(i) height:\(proxy.size.height)")
                            }
                        }
                    }
                }
                .tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
                .frame(height: 150)
                .background(.gray)
                .offset(y: offset)
                
                Spacer()
            }
            
            Color.brown
                .frame(height: 300)
                .offset(y: 200 + offset)
                .gesture(
                    DragGesture()
                        .onChanged({ value in
                            offset = value.translation.height + startY
                        })
                        .onEnded({ value in
                            startY = offset
                        })
                )
        }
                
    }
}

I hope the Tabview has a correct height,please help me.

GAP1994
  • 1
  • 1

0 Answers0