0

I want when user slides from left to right label counter updates from 1 to 5. If I swipe slowly, very slowly it works, faster then that and it doesn't work right? Is there another way to implement this?

I have this code:

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    gestureStartPoint = [touch locationInView:self.view];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [touches anyObject];
    CGPoint currentPosition = [touch locationInView:self.view];

    if ((int)(currentPosition.x)%40 == 0 && counter < 5) {
        counter++;
    }

    [label setText:[NSString stringWithFormat:@"%d", counter]];

}
Venk
  • 5,949
  • 9
  • 41
  • 52
1337code
  • 169
  • 1
  • 3
  • 11

1 Answers1

5

You can use UIPanGestureRecognizer... it has begin state ,change state and end state like as touchEvents...

- (void)onDraggingLetter:(UIPanGestureRecognizer *)panGR {

    if (panGR.state == UIGestureRecognizerStateBegan) {

    } else if (panGR.state == UIGestureRecognizerStateChanged) {  

    } else if (panGR.state == UIGestureRecognizerStateEnded) {

    }
}

it may helps you....

Venk
  • 5,949
  • 9
  • 41
  • 52