touchesMoved工作不够快

时间:2012-10-27 11:24:45

标签: iphone ios counter slide touchesmoved

我希望当用户从左到右标签计数器从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]];

}

1 个答案:

答案 0 :(得分:5)

你可以使用UIPanGestureRecognizer ...它已经开始状态,改变状态和结束状态就像触摸事件......

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

    if (panGR.state == UIGestureRecognizerStateBegan) {

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

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

    }
}

它可能对你有帮助....