Is there a good code example (or documentation) that shows how to detect long presses done by multiple fingers at the (almost) same time.
I would like to draw a circle around each finger.
With long press and drag gesture chained gives me the location of one long press. I want to know how to do it for multiple long presses.
This is the code I have now for detecting long presses and getting their location on the screen.
struct ContentView: View {
@State private var showCircle = false
@State private var tapLocation = CGPoint.zero
var longPressed: some Gesture {
LongPressGesture(minimumDuration: 1)
.sequenced(
before: DragGesture(
minimumDistance: 0,
coordinateSpace: .local
)
)
.onEnded { value in
switch value {
case .second(true, let drag):
tapLocation = drag?.location ?? .zero
showCircle = true
default:
break
}
}
}
var body: some View {
ZStack {
Rectangle()
.foregroundColor(Color(.background))
.ignoresSafeArea()
.gesture(longPressed)
.overlay(
Circle()
.foregroundColor(Color.random())
.frame(width: 100, height: 100)
.position(tapLocation)
.opacity(showCircle ? 1 : 0 )
.allowsHitTesting(false)
)
VStack(spacing: 8) {
Image(systemName: "hand.tap")
.imageScale(.large)
.foregroundStyle(.tint)
.font(.largeTitle)
Text("Tap and hold to start")
}
.padding()
}
}
}