2012-04-21 53 views
3

我有下面的代碼,我添加UITapGestureRecognizer我的看法:UIButtons UITapGestureRecognizer後,將無法正常工作添加

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self 
                     action:@selector(userTapped)]; 

[self.view addGestureRecognizer:tap]; 

我的問題是,當我按其它UIButton S(按鈕是在IB創建)與UITapGestureRecognizer的觀點相同,沒有任何反應。

我想我只向gestureRecognizer添加一個動作(userTapped :),但是如何添加與創建的其他按鈕的交互?

+0

我的想法是未來:我需要創建一些backgroundVIew,並在其中添加GestureRecognizer – ignotusverum 2012-04-21 16:16:50

回答

5

嘗試

tap.cancelsTouchesInView = NO; 

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch 
{ 
     if([touch.view isKindOfClass:[UIButton class]]) 
      return NO; 
     return YES; 
} 
+0

謝謝,這個作品! – ignotusverum 2012-04-21 16:20:06

相關問題