在我的应用程序中,我有一张图片和一个 UITextView
.
我创建了一个 UITapGestureRecognizer
对于这两种 View ,但问题是无论我在屏幕上单击什么位置,只有与 UITextView
关联的方法被执行。
即使我点击图片,也只有 UITapGestureRecognizer
与 UITextView
关联的方法被执行。
以下是我实现的代码:
UITapGestureRecognizer *tapGestureRecognizerImage = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleTapFromImage:)];
[infobutton addGestureRecognizer:tapGestureRecognizerImage];
[[self view] addGestureRecognizer:tapGestureRecognizerImage];
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleTapFrom:)];
[messageOne addGestureRecognizer:tapGestureRecognizer];
[[self view] addGestureRecognizer:tapGestureRecognizer];
//The following are the methods associated
- (void) handleTapFrom: (UITapGestureRecognizer *)recognizer {
//Code to handle the gesture
NSLog(@"I am in handleTapFrom method");
}
- (void) handleTapFromImage: (UITapGestureRecognizer *)recognizer {
//Code to handle the gesture
NSLog(@"I am in handleTapFrom Image method");
[self.view makeToast:@"Your verification code does not match. Re-enter your verification code"];
}
我确定我在这里遗漏了一些东西。
据我所知, Storyboard中的关联是正确的。
请纠正我哪里出错了
谢谢你的时间
最佳答案
您不应该在 self.view 上添加手势。
它应该被添加到您想要识别点击事件的 View 中。
关于iOS - TapGestureRecognizer - 点击适用于整个屏幕而不是 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20538542/