nOk*_*nOk 5 gesture swift swiftui
我试图从 SwiftUI 的左侧识别 EdgePan。我知道有一些手势,但无法将它们应用于整个屏幕。(尝试使用 DragGesture)。是否可以在 SwiftUI 中实现 EdgePan?或者我如何使用 DragGesture 来做同样的事情?
是的,这可以通过DragGesture.
DragGesture有一个startLocation属性,它是CGPoint. 由此,您可以检测手势的开始位置,并使用它可以确定它是否从边缘开始。
获取现有的DragGesture,并在.onChanged闭包中传入gesture,并使用 找到起始位置gesture.startLocation。因为要检测的边缘,你会想的x财产gesture.startLocation。
它看起来像这样:
DragGesture()
.onChanged({gesture in
if gesture.startLocation.x < CGFloat(100.0){
print("edge pan")
}
}
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1224 次 |
| 最近记录: |