【发布时间】:2019-12-21 04:14:23
【问题描述】:
我试图在 SwiftUI 中从左侧识别 EdgePan。我知道有一些手势,但无法将它们应用于整个屏幕。 (尝试使用 DragGesture)。 是否可以在 SwiftUI 中实现 EdgePan? 或者我如何使用 DragGesture 来做同样的事情?
【问题讨论】:
我试图在 SwiftUI 中从左侧识别 EdgePan。我知道有一些手势,但无法将它们应用于整个屏幕。 (尝试使用 DragGesture)。 是否可以在 SwiftUI 中实现 EdgePan? 或者我如何使用 DragGesture 来做同样的事情?
【问题讨论】:
是的,DragGesture 可以做到这一点。
DragGesture 有一个startLocation 属性,即CGPoint。从中,您可以检测手势从哪里开始,并使用它来确定它是否从边缘开始。
取你现有的DragGesture,在.onChanged闭包中,传入gesture,然后用gesture.startLocation找到起始位置。由于您想检测边缘,因此您需要gesture.startLocation 的x 属性。
看起来像这样:
DragGesture()
.onChanged({gesture in
if gesture.startLocation.x < CGFloat(100.0){
print("edge pan")
}
}
)
【讨论】:
.onEnded