主页 Detecting the Direction of a UIPanGesture
Post
Cancel

Detecting the Direction of a UIPanGesture

Preface

These past few days I ran into a problem: when a pan gesture is applied to a view, I couldn’t distinguish its direction.

So I found the answer on StackOverflow and documented it here.

1
2
3
4
5
6
7
8
9
10
11
12
13
- (void)panRecognized:(UIPanGestureRecognizer *)rec
{
    CGPoint vel = [rec velocityInView:self.view];
    if (vel.x > 0)
    {
        // user dragged towards the right
    }
    else
    {
        // user dragged towards the left
    }
}

Reference

该博客文章由作者通过 CC BY 4.0 进行授权。