2013-03-07 74 views
0
UITapGestureRecognizer *PressRecognizer1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handlePress:)]; 
     [PressRecognizer1 setNumberOfTouchesRequired:1]; 
     [firstBtn addGestureRecognizer:PressRecognizer1]; 

-(void)handlePress:(UITapGestureRecognizer*)PressRecognizer { 

    NSLog(@"working"); 
     if (PressRecognizer.state == UIGestureRecognizerStateBegan) { 
      UIButton *whichButton=(UIButton *)[PressRecognizer view]; 
      NSLog(@"whichButton %d\n",whichButton.tag); 
      if (whichButton.tag == 0) { 
       NSLog(@"currentImageId1 %d",currentImageId1); 
       [delegate imageZoom:currentImageId1]; 
      } 

工作我已創建了customcell其上的圖像hadlePress方法具有每row.When抽頭三個圖像一個UITabelView called.But如果條件i未進來第一個。UITapGestureRecognizer不與的UIButton

+0

@rckoenes沒有ü哪裏編輯我的代碼? – user2134883 2013-03-07 10:55:59

+0

「UITapgesture不能處理圖像」 - 代碼中的圖像在哪裏? – 2013-03-07 10:59:47

+0

我在按鈕上添加了圖像。 – user2134883 2013-03-07 11:00:57

回答

1

從蘋果文檔:

儘管抽頭是離散的手勢,它們是分立的手勢識別的每個狀態;因此相關聯的動作消息在手勢開始時發送並針對每個中間狀態發送,直到(並且包括)手勢的結束狀態。因此,處理的輕敲姿勢代碼應該測試手勢的狀態,例如:

- (void)handleTap:(UITapGestureRecognizer *)sender { 
    if (sender.state == UIGestureRecognizerStateEnded)  
    {   
      // handling code  
    } 
} 

,如果你的NSLog(@「%d」,sender.state)裏面的方法(前if語句)你」 LL看到,該方法只獲得與UIGestureRecognizerStateEnded狀態發射,因此,你應該改變你的

if (PressRecognizer.state == UIGestureRecognizerStateBegan) 

if (PressRecognizer.state == UIGestureRecognizerStateEnded) 
+0

你的答案解決了我的問題。感謝您的幫助 – user2134883 2013-03-07 11:50:21

相關問題