touchesMoved工作不够快

133*_*ode 0 iphone counter slide touchesmoved ios

我想当用户从左到右标签计数器从1到5更新时.如果我慢慢地滑动,非常缓慢地工作,然后更快,它不能正常工作?还有其他方法可以实现吗?

我有这个代码:

-(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]];

}
Run Code Online (Sandbox Code Playgroud)

Ven*_*enk 5

您可以使用UIPanGestureRecognizer...它具有开始状态,更改状态和结束状态,如touchEvents ...

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

    if (panGR.state == UIGestureRecognizerStateBegan) {

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

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

    }
}
Run Code Online (Sandbox Code Playgroud)

它可能会帮助你......