【发布时间】:2019-11-10 00:06:38
【问题描述】:
我试图检测手指何时第一次接触 SwiftUI 中的视图。我可以使用 UIKit Events 轻松做到这一点,但在 SwiftUI 中无法解决。
我尝试了最小移动为 0 的 DragGesture,但在您的手指移动之前它仍然不会改变。
TapGesture 仅在您抬起手指时才会起作用,而且无论我将参数设置为什么,LongPressGesture 都不会足够快地触发。
DragGesture(minimumDistance: 0, coordinateSpace: .local).onChanged({ _ in print("down")})
LongPressGesture(minimumDuration: 0.01, maximumDistance: 100).onEnded({_ in print("down")})
我想在手指接触到视图时立即检测到 touchDown 事件。 Apple 的默认手势对距离或时间都有限制。
更新:这不再是问题了,因为 Apple 似乎更新了 DragGesture 的工作方式,或者我可能遇到了特定的上下文错误。
【问题讨论】:
-
必须在 TapGesture 上加上 .updating 修饰符,但不知道怎么做。