2012-10-27 82 views
0

我希望用戶從左側滑動到右側標籤計數器的更新從1到5.如果我慢慢地滑動,速度非常慢,速度會更快,而且不能正常工作?有沒有另外一種方法來實現這一點?touchesMoved工作速度不夠快

我有這樣的代碼:

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

使用手勢識別器! UITouch是如此老派! – MCKapur

+0

但我如何計算UISwipeGestureRecognizer中的座標? 我希望標籤在刷卡時從1更新爲5 – 1337code

回答

5

您可以使用UIPanGestureRecognizer ......它開始的狀態,改變狀態和最終狀態等作爲touchEvents ...

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

    if (panGR.state == UIGestureRecognizerStateBegan) { 

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

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

    } 
} 

它可以幫助你...

+0

將嘗試並讓您知道;) – 1337code