swiftui-拖动手势没有在hstack上激活带有按钮的hstack
我有一个带有按钮的hStack,如这样的定义:
GeometryReader { proxy in
HStack {
Button("test")
.frame(width: 100, height: 50)
Button("test")
.frame(width: 100, height: 50)
Button("test")
.frame(width: 100, height: 50)
}
.frame(width: proxy.size.width)
.gesture(
.onChanged { gesture in
// do something here
}
)
}
如您所见,当拖动HSTACK时,我正在尝试执行一些功能。如果用户从HSTACK中的空白空间开始拖动,则可以工作,但是,如果拖动从按钮开始,则不会激活手势。我该如何解决?
I have an HStack with buttons in it defined like this:
GeometryReader { proxy in
HStack {
Button("test")
.frame(width: 100, height: 50)
Button("test")
.frame(width: 100, height: 50)
Button("test")
.frame(width: 100, height: 50)
}
.frame(width: proxy.size.width)
.gesture(
.onChanged { gesture in
// do something here
}
)
}
As you can see, I am trying to perform some function when the HStack is dragged. This works if the user drags starting from an empty space in the HStack, however, if the drag starts from the button, the gesture is not activated. How can I fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
ontapgesture
而不是按钮的视图。尝试这样的事情:
您可能还可以在拖动时尝试禁用该按钮,然后在拖动后启用。
祝你好运!
You can use a View with an
onTapGesture
instead of a button.Try something like this:
You could possibly also try and disabling the button when dragging and then enable when you're done dragging.
Good luck!