首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >touchesMoved检测无法正常工作

touchesMoved检测无法正常工作
EN

Stack Overflow用户
提问于 2012-07-20 10:31:46
回答 2查看 281关注 0票数 0

在我的应用程序中,我使用touchesMoved方法来检测向左/向右滑动。当用户连续向左和向右滑动时,图像动画会自动更新。我能够检测到滑动动作,但有时当我开始连续向左和向右滑动时,屏幕不会检测到触摸移动事件。

在滑动区域,我放置了一个隐藏按钮和一些用于动画的ImageViews。我想知道为什么它happens.please帮助我。

谢谢。

代码:

代码语言:javascript
复制
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    [super touchesMoved:touches withEvent:event];

    UITouch *touch = [touches anyObject];   
    CGPoint newLocation = [touch locationInView:self.view];
    CGPoint oldLocation = [touch previousLocationInView:self.view];

    if(newLocation.x-oldLocation.x>0){
        swipe_direction = 1;
        //NSLog(@"left");
    }
    else{
        swipe_direction = 2;
        //NSLog(@"right");

    }

    if(swipe_direction == 1){
        //animate images
    }
    else if(swipe_direction == 2){
        //animate images
    }
}
EN

回答 2

Stack Overflow用户

发布于 2012-07-20 12:31:42

touchesMoved仅检测视图的空白部分。因此,它不会检测到您使用的对象。

在视图上放置一个SwipeGestureRecognizer并从那里使用它。

票数 1
EN

Stack Overflow用户

发布于 2012-07-20 10:47:16

您是否考虑过使用SwipeGestureRecognizer而不是touchesMoved?

检查Documentation

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11572057

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档