简体   繁体   English

如何检测 EdgePan Gesture SwiftUI

[英]How to detect EdgePan Gesture SwiftUI

Im trying to recognize a EdgePan from the left in SwiftUI.我试图从 SwiftUI 的左侧识别 EdgePan。 I know there are some gestures but haven't been able to apply them to the whole screen.我知道有一些手势,但无法将它们应用于整个屏幕。 (Tried with DragGesture). (尝试使用 DragGesture)。 Is it possible to implement an EdgePan in SwiftUI?是否可以在 SwiftUI 中实现 EdgePan? Or how can I use DragGesture to do the same?或者我如何使用 DragGesture 来做同样的事情?

Yeah, this is possible with a DragGesture .是的,这可以通过DragGesture

DragGesture has a startLocation property, which is a CGPoint . DragGesture有一个startLocation属性,它是一个CGPoint From this, you can detect where the gesture started, and using this you can determine if it started from an edge.由此,您可以检测手势的开始位置,并使用它可以确定它是否从边缘开始。

Take your existing DragGesture , and in the .onChanged closure, pass in gesture , and find the start location with gesture.startLocation .使用现有的DragGesture ,并在.onChanged闭包中,传入gesture ,并使用gesture.startLocation找到起始位置。 Since you want to detect an edge, you'll want the x property of gesture.startLocation .由于您想检测边缘,因此您需要gesture.startLocationx属性。

It looks like this:它看起来像这样:

DragGesture()
    .onChanged({gesture in
        if gesture.startLocation.x < CGFloat(100.0){
            print("edge pan")
        }
     }
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM