Question

I heard that UISwipeGestureRecognizer can be used to distinguish between a slow swipe and a fast flick. But I can't find any API to tell the difference.

Was it helpful?

Solution

Do you specifically need to use UISwipeGestureRecognizer, or can you use UIPanGestureRecognizer instead? UIPanGestureRecognizer gives you precise movement data whereas UISwipeGestureRecognizer is more basic and just detects whether or not a swipe happened (and in which direction).

UIPanGestureRecognizer has a -velocityInView: method which returns a CGPoint, expressing points per second, vertically and horizontally.

OTHER TIPS

You should use Pan Gesture and find out velocity for better accuracy.

Here is code snip for PanGesture in Swift 5

//Add Pan Gesture on target view in viewDidLoad
        let panGesture = UILongPressGestureRecognizer(target: self, action: #selector(self.panGestureDetected))
        view.addGestureRecognizer(panGesture)

@objc func panGestureDetected()
    {
        print("Pan Gesture detected!!")
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top