2013-03-21 390 views
1

有没有办法确保任何包含超过一定移动量的敲击被丢弃?就这一点而言,作为水龙头的重要性可能涉及手指的大量滑动。我想通过使用touchesBegan :, touchesMoved:等来处理不同的“点按和移动”。iOS设置移动手势识别器的移动容差

+0

'UITapGestureRecognizer'有这个内置的,什么是失败? – Fogmeister 2014-05-28 15:25:38

+0

您是否在说'UITapGestureRecognizer'允许您设置公差作为轻敲? – AbleArcher 2014-06-01 21:16:57

+0

据我所知,它具有内置的容差。无论是新闻的长度还是距离的移动。离开我的头顶我不记得它是什么,但我可能会尝试看看我能否解决问题。 – Fogmeister 2014-06-02 05:38:15

回答

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 
+0

更好的做法是将此功能构建到自定义手势识别器中。请参阅WWDC 2012:构建高级手势识别器。 – olynoise 2014-05-23 20:02:07