【问题标题】:Disable Horizontal scrolling on using PageTabViewStyle for tabView swiftui使用 PageTabViewStyle 为 tabView swiftui 禁用水平滚动
【发布时间】:2022-11-17 13:49:12
【问题描述】:

这就是我的 tabView 的样子。我希望视图具有页面感觉,这就是我使用 PageTabViewStyle 的原因,但我不希望页面在用户滑动时可滚动。

如何禁用视图上的水平滑动/拖动?```

TabView(选择:$tabIndex){

                PasswordCardView(tabIndex: $tabIndex,
                                 fieldType: $fieldType,
                                 shouldClearPasswords: $shouldClearPasswords,
                                 isHorizontalDrag: $isHorizontalDrag)
                .padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
                .tag(0)
                .contentShape(Rectangle())
         
                
                
                UserNameCardView(tabIndex: $tabIndex,
                                 fieldType: $fieldType)
                .padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
                .tag(1)
                .contentShape(Rectangle())
                
                BirthdayCardView(tabIndex: $tabIndex,
                                 fieldType: $fieldType,
                                 tapGesturePerformed: $tapGesturePerformed,
                                 isHorizontalDrag: $isHorizontalDrag)
                .padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
                .tag(2)
                .contentShape(Rectangle())
                
                GenderCardView(tabIndex: $tabIndex,
                               fieldType: $fieldType,
                               tapGesturePerformed: $tapGesturePerformed)
                .padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
                .tag(3)
                .contentShape(Rectangle())
                
                LocationCardView(tabIndex: $tabIndex,
                                 fieldType: $fieldType,
                                 isSignUpShown: $isSignUpShown)
                .padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
                .tag(4)
                .contentShape(Rectangle())
                
                NewsletterCardView(tabIndex: $tabIndex,
                                   fieldType: $fieldType)
                .padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
                .tag(5)
                .contentShape(Rectangle())
                
                ActivationCardView(tabIndex: $tabIndex,
                                   fieldType: $fieldType,
                                   dismissSignup: $dismissSignup)
                .padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
                .tag(6)
                .contentShape(Rectangle())
            }
        .tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))




I've tried making the x offset to 0, but that unhooks the tabview's vertical scrolling with the entire view's scrolling. That is on vertical swiping the tabview, it hides being the other views in parent view.

I've tried to remove the dragGesture() if the drag is horizontal:-
.gesture(isHorizontalDrag ? DragGesture() : nil)

but that also doesn't work everytime, by the time the gesture gets recognised, the gesture is already set in tabView

【问题讨论】:

    标签: swift swiftui swiftui-tabview swiftui-scrollview


    【解决方案1】:

    我最终不得不使用名为 introspect 的第 3 方库来让它工作。这允许我们停止在一个方向上滚动。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-13
      • 1970-01-01
      • 2021-04-07
      • 2012-05-05
      • 2014-05-11
      • 2015-03-26
      • 1970-01-01
      相关资源
      最近更新 更多