Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In my app there is a image view.Im adding PAN gesture to that image view.

This is working fine.

The image view is in landscape mode.

I want to increase a count in label while user pan to right direction and decrease that count while user pan to left direction.

I googled a lot but didn't find a solution for this.

Can anyone please help me how to detect the direction in which the user is panning(left/right)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
550 views
Welcome To Ask or Share your Answers For Others

1 Answer

In the target selector of your gesture recognizer, use - (CGPoint)velocityInView:(UIView *)view;:

- (void)panRecognized:(UIPanGestureRecognizer *)rec
{
    CGPoint vel = [rec velocityInView:self.view];
    if (vel.x > 0)
    {
        // user dragged towards the right
        counter++;
    }
    else
    {
        // user dragged towards the left
        counter--;
    }
}

P.s.: I didn't know about this method until approx. 3 minutes before. One of Google's first hits was the official Apple documentation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...