OGeek|极客世界-中国程序员成长平台

标题: iphone - UIButton Action 不使用 UITapGestureRecognizer iphone 应用程序调用? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 15:08
标题: iphone - UIButton Action 不使用 UITapGestureRecognizer iphone 应用程序调用?

我正在使用 UITapGestureRecognizer 和 UIButton 在 iPhone 应用程序中工作。我在 self.view 中添加了 UITapGestureRecognizer。当我单击 UIButton 时,它不会调用它的 Action ,仅调用 Tapgesture Action 。如何解决这个问题?有人可以帮忙解决这个问题吗?

这是我在 -ViewDidLoad 中的代码,

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self actionselector(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 actionselector(infoAlert forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside];
    [toolBarView1 addSubview:infoButton1]; 

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


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

请帮我解决这个问题。提前致谢。



Best Answer-推荐答案


为什么没有人使用堆栈溢出或谷歌的奇妙搜索?

这是您的答案:https://stackoverflow.com/a/3348532/312312

在同一个线程中,这似乎是一个更简单的解决方案: https://stackoverflow.com/a/8891030/312312

关于iphone - UIButton Action 不使用 UITapGestureRecognizer iphone 应用程序调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11631827/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4