Im trying to recognize a EdgePan from the left in SwiftUI. I know there are some gestures but haven't been able to apply them to the whole screen. (Tried with DragGesture). Is it possible to implement an EdgePan in SwiftUI? Or how can I use DragGesture to do the same?
A pan gesture occurs any time a person moves one or more fingers around the screen. A screen-edge pan gesture is a specialized pan gesture that originates from the edge of the screen. Use the UIPanGestureRecognizer class for pan gestures and the UIScreenEdgePanGestureRecognizer class for screen-edge pan gestures.
Yeah, this is possible with a DragGesture
.
DragGesture
has a startLocation
property, which is a 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
. Since you want to detect an edge, you'll want the x
property of gesture.startLocation
.
It looks like this:
DragGesture()
.onChanged({gesture in
if gesture.startLocation.x < CGFloat(100.0){
print("edge pan")
}
}
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With