使用UIKit时,我在UIView或UIViewController中进行处理。
func touchesBegan(_ touches:设置,事件:UIEvent?)
如何使用SwiftUI处理触摸事件?
最简单的方法是添加一个DragGesture。 签出 DragGesture.Value了解您所拥有的信息。
Circle()
.gesture(
DragGesture(minimumDistance: 5, coordinateSpace: .global)
.onChanged { value in
self.dragLocation = value.location
}
.onEnded { _ in
self.dragLocation = .zero
}
)
Run Code Online (Sandbox Code Playgroud)
您可以使用minimumDistance: 0来使手势立即开始更新,类似于touchesBegan(...)UIKit。
| 归档时间: |
|
| 查看次数: |
924 次 |
| 最近记录: |