5

I am trying to build an app that shows different days of the week in a paged tab view, but when I scroll sideways to a day (e.g. Tuesday), I can scroll it up and down as if it was a scroll view. I don't have a scroll view in my content view.

My code is something like this:

struct ContentView: View {
    var body: some View {
        TabView {
            Text("Saturday")
            Text("Sunday")
            Text("Monday")
            Text("Tuesday")
            Text("Wednesday")
            Text("Thursday")
            Text("Friday")
        }
        .tabViewStyle(PageTabViewStyle())
    }
}
mkrieger1
  • 19,194
  • 5
  • 54
  • 65

1 Answers1

3

You can do that like this

Put TabView inside the ScrollView with .onAppear()

.onAppear(perform: {
            UIScrollView.appearance().alwaysBounceVertical = false
})  

struct ContentView: View {
    var body: some View {
        ScrollView(.vertical, showsIndicators: false) {
            TabView {
                Text("Saturday")
                Text("Sunday")
                Text("Monday")
                Text("Tuesday")
                Text("Wednesday")
                Text("Thursday")
                Text("Friday")
            }
            .tabViewStyle(PageTabViewStyle())
            .frame(width: 300, height: 600, alignment: .center)
        }
        .frame(width: 300, height: 600, alignment: .center)
        .background(Color.blue)
        .onAppear(perform: {
            UIScrollView.appearance().alwaysBounceVertical = false
        })
    }
}

enter image description here

Taeeun Kim
  • 964
  • 1
  • 8
  • 20