且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 SwiftUI 中向 ScrollView 内的视图添加拖动手势会阻止滚动

更新时间:2023-11-18 13:57:58

您可以将 minimumDistance 设置为某个值(例如 30).那么只有在水平拖动并达到最小距离时拖动才起作用,否则滚动视图或列表手势会覆盖视图手势

You can set minimumDistance to some value (for instance 30). Then the drag only works when you drag horizontally and reach the minimum distance, otherwise the scrollview or list gesture override the view gesture

.gesture(DragGesture(minimumDistance: 30, coordinateSpace: .local)