2

UITapGestureRecognizerとUIButtonを使用してiPhoneアプリケーションで作業しています。self.viewにUITapGestureRecognizerを追加しました。UIButtonをクリックしても、そのアクションは呼び出されません。タプジェスチャアクションのみが呼び出されます。この問題を解決する方法は?誰かがこの問題を解決するのを手伝ってもらえますか?

これが私のコードです-ViewDidLoad

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapFrom:)];
    [self.view addGestureRecognizer:tapRecognizer];
    [tapRecognizer release];

UIButton *infoButton1 = [UIButton buttonWithType:UIButtonTypeInfoDark];
    infoButton1.frame = CGRectMake(0, 5, 30, 30);
    infoButton1.tag = 1;
    infoButton1.opaque = YES;
    [infoButton1 addTarget:self action:@selector(infoAlert:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside];
    [toolBarView1 addSubview:infoButton1]; 

-(void) infoAlert:(id) sender
{
    NSLog(@"Get Info Alert"); // Here the control not calling..
}


-(void)handleTapFrom:(UITapGestureRecognizer *)recognizer
{    
    NSLog(@"%@",[NSString stringWithFormat:@"%d", recognizer.view.tag]); // Whenever i touch the button this method only calling.
}

この問題を解決するのを手伝ってください。前もって感謝します。

4

2 に答える 2

3

スタックオーバーフローやグーグルの素晴らしい検索を使用している人がいないのはなぜですか?

これがあなたの答えです:https ://stackoverflow.com/a/3348532/312312

そして同じスレッドから、これはさらに簡単な解決策のようです: https ://stackoverflow.com/a/8891030/312312

于 2012-07-24T13:27:54.947 に答える
0

これが最善の解決策です。tapRecognizerを宣言した後(質問のコードを参照しています)、次を追加します。

  tapRecognizer.cancelsTouchesInView = NO;
于 2015-05-23T16:11:50.140 に答える