I am trying to drag a view in SwiftUI.
The drag works perfectly until I place my second finger on screen, after that the drag stops and neither of the code blocks (onChanged
, onEnded
) gets called.
But, when I again start dragging with a single finger, it again starts working.
Is there any work around to fix this or I am missing something?
struct Pager: View {
func drag(geometry: GeometryProxy) -> some Gesture {
DragGesture()
.onChanged({ (value) in
//some code
})
.onEnded({ (value) in
//some code
})
}
var body: some View {
GeometryReader { (geometry) in
ZStack {
ForEach(self.items.indices.reversed(), id: \.self) { index in
Card(index: index, item: self.items[index])
.offset(x: 0, y: self.offset(index: index, geometry: geometry))
.animation(.linear)
}
}
.background(Color.black)
.gesture(self.drag(geometry: geometry))
}
}
}