How to Handle Duration Time Long Pressed SwiftUI

Viewed 31

.gesture(LongPressGesture(minimumDuration: 0, maximumDistance: 10.0) .onChanged(){})

1 Answers

Hi here is example for change duration of gesture according to your need :


      Rectangle()
            .fill(isPressing ? Color.orange : .gray)
            .frame(width: 50, height: 30)
            .onLongPressGesture(minimumDuration: 0.25, maximumDistance: 50, pressing: { (isPressing) in
            if isPressing {
                // called on touch down
            } else {
                // called on touch up
                message = "TAP"
            }
        }, perform: {
            message = "LONG\nPRESS"
        })

 
Related