我有一个带有两个手势识别器的UIView。两者都用两个手指识别敲击:一个用于屏幕的上半部分,另一个用于屏幕的底部。 在那个UIView中,我有4个按钮覆盖整个屏幕(每个按钮是屏幕的四分之一)。
我正在使用手势识别器来检测用户何时同时按下2个按钮,我仍然想要识别按钮上的正常触摸。
我已经设置了所有内容,并且工作正常。但是,只用一根手指按下按钮上的阴影就会出现在Touch Up上,而不会出现在Touch Down上。这感觉很奇怪。我试图改变延迟,但是没有成功。
有没有办法同时拥有这两种行为?用两根手指检测触摸,但只有一根手指时有“正常行为”?否则,我可以强制按下UI按钮的状态吗?
以下是我设置手势的方法:
-(void)initGestureRecognition{
handClapTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handClapDetected:)];
handClapTapGestureRecognizer.numberOfTouchesRequired = 2;
handClapTapGestureRecognizer.numberOfTapsRequired = 1;
handClapTapGestureRecognizer.cancelsTouchesInView = YES;
[self.gestureRecognitionView addGestureRecognizer:handClapTapGestureRecognizer];
handClapTapGestureRecognizer.delegate = self;
jumpTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(jumpDetected:)];
jumpTapGestureRecognizer.numberOfTouchesRequired = 2;
jumpTapGestureRecognizer.numberOfTapsRequired = 1;
jumpTapGestureRecognizer.cancelsTouchesInView = YES;
[self.gestureRecognitionView addGestureRecognizer:jumpTapGestureRecognizer];
jumpTapGestureRecognizer.delegate = self;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return NO;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
if ([gestureRecognizer isEqual:handClapTapGestureRecognizer] && [touch locationInView:self.view].y > self.view.frame.size.height/2)
return NO;
if ([gestureRecognizer isEqual:jumpTapGestureRecognizer] && [touch locationInView:self.view].y < self.view.frame.size.height/2)
return NO;
return YES;
}
我知道我的问题类似于那个问题:UIButton inside a view that has a UITapGestureRecognizer但不同的是,在我的情况下,行为是正常的,而我只是试图在Touch DOwn上的按钮上获得阴影,而不是而不是Touch Up。
由于
答案 0 :(得分:1)
首次识别点击手势并且其位置与按钮的位置匹配时,您是否可以手动设置[button setHighlighted:YES]
,然后在手势结束时设置为NO
?