What gesture can execute code only while user placing their finger on the screen in SwiftUI?

Viewed 48

What gesture can execute code only while user placing their finger on the screen?

Running certain code should not be Effect of the Cause(gesture), what I want is running certain code while user holding their finger on the screen, and if the user took their finger off the code stops running

For example,

//some view
.unknownGesture{
// running this code only while user placing their finger on the screen
}
1 Answers

Here is possible solution

.gesture(
  DragGesture(minimumDistance: 0)
    .onChanged() { event in
      print(">>> activated")
    })
Related