iphone - UIButton Action 不使用 UITapGestureRecognizer iPhone 应用程序调用?

标签 iphone ios uibutton uitapgesturerecognizer

我正在使用 UITapGestureRecognizer 和 UIButton 开发 iPhone 应用程序。我在 self.view 中添加了 UITapGestureRecognizer。当我单击 UIButton 时,它不会调用它的操作,仅调用 Tapgesture 操作。如何解决这个问题呢?谁能帮忙解决这个问题吗?

这是我在 -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.
}

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

最佳答案

为什么没有人使用 Stack Overflow 或 Google 的精彩搜索?

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

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

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

相关文章:

ios - shouldChangeCharactersInRange 行为异常

ios - CVPixelBuffer 使用 UIImage.draw() 编写太慢

ios - 如何将两个 UILabel 排成一行,以便它们根据 iOS 中文本的大小垂直居中?

ios - 如何减小视频大小 - iOS Titanium 视频?

iphone - 交替控制+拖动以在 xCode 界面生成器中将 View 元素与文件所有者连接?

iphone - 无效的应用程序二进制文件

ios - UIButton 事件跟踪 Google Analytics(Swift)

iphone - iOS 4.2+ webfont (ttf) 的粗体字体渲染错误

ios - 无法在 IOS5 模拟器中编辑 UITextField

iphone - 防止禁用的 UIButton 传播触摸事件