So I have a ScrollView
holding a set of views:
ScrollView {
ForEach(cities) { city in
NavigationLink(destination: ...) {
CityRow(city: city)
}
.buttonStyle(BackgroundButtonStyle())
}
}
In every view I have a drag gesture:
let drag = DragGesture()
.updating($gestureState) { value, gestureState, _ in
// ...
}
.onEnded { value in
// ...
}
Which I assign to a part of the view:
ZStack(alignment: .leading) {
HStack {
// ...
}
HStack {
// ...
}
.gesture(drag)
}
As soon as I attach the gesture, the ScrollView
stop scrolling. The only way to make it scroll it to start scrolling from a part of it which has no gesture attached. How can I avoid it and make both work together. In UIKit is was as simple as specifying true
in shouldRecognizeSimultaneouslyWith
method. How can I have the same in SwiftUI?
In SwiftUI I've tried attaching a gesture using .simultaneousGesture(drag)
and .highPriorityGesture(drag)
– they all work the same as .gesture(drag)
. I've also tried providing all possible static GestureMask
values for including:
parameter – I have either scroll working or my drag gesture working. Never both of them.
Here's what I'm using drag gesture for:
question from:
https://stackoverflow.com/questions/57700396/adding-a-drag-gesture-in-swiftui-to-a-view-inside-a-scrollview-blocks-the-scroll 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…