简体   繁体   中英

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?

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")
        }
     }
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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