swiftui draggasure吞噬了scrollview

发布于 2025-01-23 16:45:38 字数 836 浏览 4 评论 0原文

我想在任何SwiftUI视图上注册某个阻力手势,包括ScrollViews同时使用任何其他手势(即不影响现有手势)。但是,当在scrollview上添加draggasture时,似乎立即被scrollview吞噬了手势。

ScrollView {
    Rectangle()
        .frame(width: 500, height: 500)
}
.simultaneousGesture(
    DragGesture()
        .onChanged { value in
            print("changed:", value.translation)
        }
        .onEnded { value in
            print("ended:", value.translation)
        }
)

当我拖动矩形时,此代码会打印:

changed: (3.0, 16.666671752929688)

例如。

因此,on Changed仅调用一次,Onedend从未调用。

是否有一种方法可以使draggestures也可以与scrollviews一起使用

注意:

我尝试找到具有gesturestate更新(_:)修饰符的解决方法,但也没有起作用。

I want to register a certain drag gesture on any SwiftUI view, including ScrollViews simultaneously with any other gestures (i.e. without influencing existing gestures). However, when adding a DragGesture on a ScrollView as follows, it seems like the gesture is immediately swallowed by the ScrollView.

ScrollView {
    Rectangle()
        .frame(width: 500, height: 500)
}
.simultaneousGesture(
    DragGesture()
        .onChanged { value in
            print("changed:", value.translation)
        }
        .onEnded { value in
            print("ended:", value.translation)
        }
)

When I drag the Rectangle, this code prints:

changed: (3.0, 16.666671752929688)

for example.

So onChanged is only called once, onEnded is never called.

Is there a way to make DragGestures work with ScrollViews as well?

Note:

I tried to find a workaround with GestureState and the updating(_:) modifier as well, but it didn't work either.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文