4

I'm trying to design a SwiftUI view that allows both horizontal and vertical swiping. Currently, I have implemented a solution using a TabView for horizontal movement and a ScrollView(.vertical) for vertical movement. However, I've noticed that the code sometimes has difficulty detecting whether I intend to perform a vertical or horizontal swipe, especially when the gesture is at an angle. As a beginner in SwiftUI, I'm looking for suggestions on how to improve the code to ensure smoother and more accurate swiping detection. I would appreciate any help or insights regarding this issue. Thank you!

struct TabViewContainer: View {
    
    @State private var currentIndex = 0
    @State private var arr:[[Int]] = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 0, 1, 2]]
    
    var body: some View {
        VStack {
            TabView(selection: $currentIndex) {
                ForEach(arr, id: \.self) { array in
                    ScrollView(.vertical) {
                        LazyVStack {
                            ForEach(array, id: \.self) { value in
                                Text(String(value))
                                    .frame(width: 300, height: 100)
                                    .background(Color.red)
                                    .padding(5)
                            }
                        }
                    }
                }
            }
            .tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
        }
    }
}
Jabed Dhali
  • 167
  • 6

0 Answers0