在 SwiftUI 中,只有当用户将手指放在屏幕上时,什么手势才能执行代码?
What gesture can execute code only while user placing their finger on the screen in SwiftUI?
什么手势只有在用户将手指放在屏幕上时才能执行代码?
运行 某些代码不应该是原因的结果(手势),我想要的是 运行 用户将手指放在屏幕上时的某些代码,如果用户拿走了他们的手指关闭代码停止 运行
例如,
//some view
.unknownGesture{
// running this code only while user placing their finger on the screen
}
这是可能的解决方案
.gesture(
DragGesture(minimumDistance: 0)
.onChanged() { event in
print(">>> activated")
})
什么手势只有在用户将手指放在屏幕上时才能执行代码?
运行 某些代码不应该是原因的结果(手势),我想要的是 运行 用户将手指放在屏幕上时的某些代码,如果用户拿走了他们的手指关闭代码停止 运行
例如,
//some view
.unknownGesture{
// running this code only while user placing their finger on the screen
}
这是可能的解决方案
.gesture(
DragGesture(minimumDistance: 0)
.onChanged() { event in
print(">>> activated")
})