0
我有一個UIView與兩個手勢識別器。兩人都用兩個手指識別敲擊:一個用於屏幕的上半部分,另一個用於屏幕的底部。 在該UIView中,我有4個覆蓋整個屏幕的按鈕(每個按鈕都是屏幕的四分之一)。手勢識別器的UIButton子視圖
我使用手勢識別器來檢測用戶何時同時按下2個按鈕,並且我仍然想要識別按鈕上的正常觸摸。
我已經安裝了一切,它工作正常。但是,只用一根手指按下按鈕上的陰影會出現在觸摸上,而不是按下。感覺很奇怪。我試圖改變延遲觸摸開始沒有成功。
有兩種行爲方式嗎?用兩根手指檢測觸摸,但只有一根手指時有「正常行爲」?否則,我可以強制按下按鈕的狀態嗎?
下面是如何設置我的手勢:
-(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上。
感謝
謝謝,它的工作原理。 不知道爲什麼我沒有想到那個... –