我正在使用一个tab view在我的 SwiftUI 应用程序中。我想要disable its swipe向左写信至move到其他页面。我检查了这个答案 https://stackoverflow.com/questions/65524458/swiftui-tabview-pagetabviewstyle-prevent-changing-tab并且还检查了this one https://stackoverflow.com/questions/63168014/swiftui-2-0-tabview-disable-swipe-to-change-page/63170431#63170431,但它们都不起作用。他们正在使用
.gesture(DragGesture())
这正在禁用left滑动。我想要禁用两者向左和向右滑动。
我也尝试过:
.禁用(真)
这会禁用整个视图。我的视图上有一些按钮可以执行一些任务。这也让他们失去了能力。
我的代码是:
@State var selectedIndex = 0
var body: some View {
TabView(selection: $selectedIndex) {
FirstView().tag(0).gesture(DragGesture())
SecondView().tag(1).gesture(DragGesture())
ThirdView().tag(2).gesture(DragGesture())
}.tabViewStyle(.page(indexDisplayMode: .never))
}
My 第一视角代码是:
func firstView() -> some View {
VStack(alignment: .leading) {
HStack {
Text("Is this a live claim?")
.font(.custom(InterFont.bold.rawValue, size: 24))
Spacer()
}.padding()
Spacer()
BlueButton(title: "Continue") {
print("pressed")
}.padding()
}.ignoresSafeArea(edges: .top)
}
My 第二视角代码是:
func secondView() -> some View {
VStack(alignment: .leading) {
HStack {
Text("Detail of the incident")
.font(.custom(InterFont.bold.rawValue, size: 24))
Text("(Optional)")
.font(.custom(InterFont.regular.rawValue, size: 14))
}.padding()
VStack(alignment: .leading) {
Text("Detail of the incident")
.font(.custom(InterFont.regular.rawValue, size: 16))
Spacer()
BlueButton(title: "Continue", action: {
print("continue pressed")
})
}.padding()
}.ignoresSafeArea(edges: .top)
}
My 第三视角代码是:
func thirdView() -> some View {
VStack(alignment: .leading, spacing: 20) {
VStack(spacing: -10) {
HStack{
Text("Call Police Crime Number")
.font(.custom(InterFont.bold.rawValue, size: 14))
Spacer()
Text("101")
.font(.custom(InterFont.bold.rawValue, size: 14))
.underline()
}.padding()
}
Spacer()
BlueButton(title: "Continue") {
print("continue pressed")
}.padding()
}.ignoresSafeArea(edges: .top)
}
有人有解决方案吗?