iOS设置轻敲手势识别器的移动公差
是否有办法确保丢弃任何包含超过一定移动量的水龙头?事实上,一次轻敲可能需要大量的手指滑动。我想通过使用touchsbegind:,touchsmoved:,等,以不同的方式处理点击和移动。可能不是您想要的答案。但我已经解决了这个问题,而是自己按常规的触摸顺序来做。要使其工作,您还需要self.multipleTouchEnabled=NOiOS设置轻敲手势识别器的移动公差,ios,uigesturerecognizer,Ios,Uigesturerecognizer,是否有办法确保丢弃任何包含超过一定移动量的水龙头?事实上,一次轻敲可能需要大量的手指滑动。我想通过使用touchsbegind:,touchsmoved:,等,以不同的方式处理点击和移动。可能不是您想要的答案。但我已经解决了这个问题,而是自己按常规的触摸顺序来做。要使其工作,您还需要self.multipleTouchEnabled=NO @interface myView(){ CGPoint _touchStartPoint; } @end @implementation myVi
@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
更好的做法是将此功能构建到自定义手势识别器中。请参阅WWDC 2012:构建高级手势识别器。UITapGestureRecognizer内置了此功能,失败的原因是什么?您是说UITapGestureRecognizer允许您为算作抽头的内容设置容差?据我所知,它内置了容差。同时适用于压具长度和移动距离。我一时想不起来是什么,但我可能会尝试一下,看看我是否能解决这个问题。如果你想轻拍并移动,那么使用平移手势识别器。你会被告知它何时开始,何时移动,何时结束。识别器的所有状态。