swiftui draggasure吞噬了scrollview
我想在任何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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论