SwiftUI 2.0 TabView 禁用滑动以更改页面 [英] SwiftUI 2.0 TabView disable swipe to change page

查看:34
本文介绍了SwiftUI 2.0 TabView 禁用滑动以更改页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 swiftUI 2.0 PageTabViewStyle 的 TabView.有什么办法可以禁止滑动换页吗?

I have a TabView thats using the swiftUI 2.0 PageTabViewStyle. Is there any way to disable the swipe to change pages?

我的第一个选项卡视图中有一个搜索栏,但是如果用户正在键入,我不想提供更改它们的功能,我基本上希望它被锁定在该屏幕上,直到所述功能完成了.

I have a search bar in my first tab view, but if a user is typing, I don't want to give the ability to change they are on, I basically want it to be locked on to that screen until said function is done.

这是一个显示差异的 gif,我希望在 gif 全屏时禁用选项卡更改.https://imgur.com/GrqcGCI

Here's a gif showing the difference, I'm looking to disable tab changing when it's full screen in the gif. https://imgur.com/GrqcGCI

推荐答案

尝试类似以下内容(使用一些存根代码进行测试).这个想法是在某些条件(在你的情况下开始编辑)发生时阻止选项卡视图拖动手势

Try something like the following (tested with some stub code). The idea is to block tab view drag gesture when some condition (in you case start editing) happens

@State var isSearching = false

// ... other code

TabView {
    // ... your code here

    Your_View()
       .gesture(isSearching ? DragGesture() : nil)  // blocks TabView gesture !!
}
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .always))

这篇关于SwiftUI 2.0 TabView 禁用滑动以更改页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆