如何仅在ScrollView中禁用滚动而不在内容视图中禁用滚动? [英] How to only disable scroll in ScrollView but not content view?
问题描述
最近,我编写了一个小的SwiftUI库,该库可以旋转View数组并选择View.
Recently I wrote a small SwiftUI library that can rotate an array of Views and select view.
但是发现了一个问题,我无法弄清楚在正常模式下如何在ScrollView中禁用滚动.
But found an issue that I can't figure out how to disable scroll in ScrollView while in normal mode.
不幸的是,我试图将 .disabled(true)
放在 ScrollView
的末尾,这不仅禁用了滚动功能,而且还禁用了ScrollView中的所有视图.
I tried to put .disabled(true)
at the end of the ScrollView
unfortunately, it not only disable scroll but also all the views in ScrollView.
此处是源代码的源代码https://github.com/raxabizze/RotateViewManager"rel =" noreferrer>项目.
Here's source code of the project.
我应该添加什么修饰符来解决这个问题?
What modifier should I add to solve this?
-已编辑-
我试图更改滚动轴,但一旦滚动轴变为[],scrollview将重置其内容偏移量,想知道是否有一种方法可以在不更改轴的情况下阻止滚动.
I have tried to change the scroll axis but once it becomes [], scrollview will reset its content offset, wondering if there's a way to block scrolling without changing the axis.
-已解决-
最后,我只添加了 DragGesture()
来阻止滚动事件并正常工作.
At last, I just add a DragGesture()
to block scroll event and works fine.
推荐答案
如果要滚动视图,则仅将 .horizontal
作为滚动轴.否则,传递空集.
Only pass .horizontal
as the scroll axis if you want the view to scroll. Otherwise, pass the empty set.
struct TestView: View {
@Binding var shouldScroll: Bool
var body: some View {
ScrollView(axes, showsIndicators: false) {
Text("Your content here")
}
}
private var axes: Axis.Set {
return shouldScroll ? .horizontal : []
}
}
这篇关于如何仅在ScrollView中禁用滚动而不在内容视图中禁用滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!