9
TabView(selection: $vm.selectedTab) {
   PlanCard_PositiveDay(vm: vm).tag(0)
   PlanCard_CountdownDay().tag(1)
   PlanCard_Basalkcal().tag(2)
   PlanCard_ActivityDiet().tag(3)
   PlanCard_Schedule().tag(4)
   PlanCard_WeightTarget().tag(5)
}
.tabViewStyle(PageTabViewStyle.init(indexDisplayMode: .never))

I use TabView with PageTabViewStyle to build a pageView, but I want to click some button to change position, not auto-scroll to change position with finger gesture, so I want to disable auto-scroll, How can I update my code To achieve this

Thx!

wanbo
  • 868
  • 9
  • 24
  • 2
    Does this answer your question? [SwiftUI 2.0 TabView disable swipe to change page](https://stackoverflow.com/questions/63168014/swiftui-2-0-tabview-disable-swipe-to-change-page) – koen Dec 09 '20 at 20:00
  • hey wanbo! did you find any answer regarding this question. I am also stuck on this – Taimoor Arif Jun 23 '22 at 07:54

1 Answers1

0

Use .contentShape modifier along with DragGesture():

TabView(selection: $vm.selectedTab) {

   PlanCard_PositiveDay(vm: vm).tag(0).contentShape(Rectangle()).gesture(DragGesture())

   PlanCard_CountdownDay().tag(1).contentShape(Rectangle()).gesture(DragGesture())

   PlanCard_Basalkcal().tag(2).contentShape(Rectangle()).gesture(DragGesture())

   PlanCard_ActivityDiet().tag(3).contentShape(Rectangle()).gesture(DragGesture())

   PlanCard_Schedule().tag(4).contentShape(Rectangle()).gesture(DragGesture())

   PlanCard_WeightTarget().tag(5).contentShape(Rectangle()).gesture(DragGesture())

}
.tabViewStyle(PageTabViewStyle.init(indexDisplayMode: .never))
Taimoor Arif
  • 750
  • 3
  • 19