1

有没有办法确保任何包含超过一定移动量的水龙头都被丢弃?事实上,所谓的轻敲可能涉及手指的大量滑动。我想通过使用 touchesBegan:、touchesMoved: 等以不同方式处理“点击和移动”。

4

1 回答 1

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
于 2014-05-23T19:48:04.383 回答