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

ぃ、小莉子 提交于 2021-01-27 19:22:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!