iphone - touchesMoved 工作速度不够快

标签 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]];

}

最佳答案

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

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

    if (panGR.state == UIGestureRecognizerStateBegan) {

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

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

    }
}

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

关于iphone - touchesMoved 工作速度不够快,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13099730/

相关文章:

javascript - 如何在 Cordova 的 WKWebView 中动态阻止/允许滑动手势导航?

ios - NSDateFormatter,中间有自定义字符串

java - (Java) 添加到计数器变量的代码

r - 创建具有多个变量的计数器

iphone - Facebook 页面就像 iOS 中一样

iphone - 指针指向不同的对象: (Unrecognized selector sent to instance)

iphone - iOS Apple 推送通知服务警告框

iphone - 改变UIIMAGE+UIKIT+iphone的颜色

ios - 从 Facebook WebView 中打开 iOS 深层链接停止工作

c - 字长计数器不将单引号计为一个字符