Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect EdgePan Gesture SwiftUI

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?

like image 884
nOk Avatar asked Aug 14 '19 15:08

nOk


People also ask

What is a Uipangesture?

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.


1 Answers

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")
        }
     }
)
like image 65
Will Avatar answered Oct 23 '22 19:10

Will