【发布时间】: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