我有两个IBActions
应用于按钮,其中一个触发触地和向下,另一个在触摸 ,但是我也有一个点击手势应用于双击上的按钮。
我已经应用了NSLog
来查看发生了什么,结果是当我双击时,触地和双击都会触发(幸运的是< em> touch up 不会触发)这是有意义的 - 但是当我双击时,如何阻止触碰?
代码示例
//fired on touch down
-(IBAction)touchdown:(id)sender
{
NSLog(@"touching down.");
}
//fired on touch up
-(IBAction)touchup:(id)sender
{
NSLog(@"taking off.");
}
//fired on double click
-(IBAction)boost:(UITapGestureRecognizer *)sender
{
NSLog(@"goodbye.");
}
答案 0 :(得分:0)
导入代理<UIGestureRecognizerDelegate>
我认为你是在viewDidLoad方法中完成的,
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(boost:)];
tapGestureRecognizer.delegate = self;
tapGestureRecognizer.numberOfTapsRequired = 2;
[self.button addGestureRecognizer:tapGestureRecognizer];
您需要根据您的降落坐标
来实现此委托方法 -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
CGPoint coords = [touch locationInView:self.button];
NSLog(@"Coords: %g, %g", coords.x, coords.y);
if (coords.y < 21 && coords.y > 25)
return NO;
else
return YES;
}