Max Wells
Max Wells

Reputation: 89

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

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
}

Upvotes: 2

Views: 66

Answers (1)

Asperi
Asperi

Reputation: 257493

Here is possible solution

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

Upvotes: 1

Related Questions