iOS设置Tap手势识别器的移动容差

时间:2013-03-21 17:43:17

标签: ios uigesturerecognizer

有没有办法确保丢弃包含超过一定运动量的任何水龙头?实际上,什么算作水龙头可能涉及手指的大量滑动。我想通过使用touchesBegan:,touchesMoved:等来处理“轻敲和移动”。

1 个答案:

答案 0 :(得分:0)

可能不是您正在寻找的答案。但是我已经解决了这个问题,而是在常规触摸序列中自己做。为此,您还需要self.multipleTouchEnabled = NO

@interface myView(){
    CGPoint _touchStartPoint;
}
@end

@implementation myView

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    _touchStartPoint = [[touches anyObject] locationInView:self];
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    [self checkDistance: [[touches anyObject] locationInView:self]];
}


-(void)checkDistance:(CGPoint)p{

    static CGFloat dX;
    dX = p.x - _touchStartPoint.x;

    static CGFloat dY;
    dY = p.y - _touchStartPoint.y;

    static CGFloat dist;
    dist = sqrt(dX*dX + dY*dY);

    /* movement of less than 10 pixels */
    if(dist < 10){
        [self tap];
    }
}

-(void)tap{
    /* do something with your tap*/
}


@end