我希望当用户从左到右滑动时,标签计数器从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]];
}发布于 2012-10-27 20:46:30
您可以使用UIPanGestureRecognizer...它有像touchEvents一样的开始状态、改变状态和结束状态。
- (void)onDraggingLetter:(UIPanGestureRecognizer *)panGR {
if (panGR.state == UIGestureRecognizerStateBegan) {
} else if (panGR.state == UIGestureRecognizerStateChanged) {
} else if (panGR.state == UIGestureRecognizerStateEnded) {
}
}它可能会帮助你..。
https://stackoverflow.com/questions/13099730
复制相似问题