问题
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:
Here is possible solution
.gesture(
DragGesture(minimumDistance: 0)
.onChanged() { event in
print(">>> activated")
})
来源:https://stackoverflow.com/questions/62221414/what-gesture-can-execute-code-only-while-user-placing-their-finger-on-the-screen