gpt4 book ai didi

iOS - TapGestureRecognizer - 点击适用于整个屏幕而不是 View

转载 作者:行者123 更新时间:2023-12-01 17:31:27 25 4
gpt4 key购买 nike

在我的应用程序中,我有一张图片和一个 UITextView .
我创建了一个 UITapGestureRecognizer对于这两种 View ,但问题是无论我在屏幕上单击什么位置,只有与 UITextView 关联的方法被执行。
即使我点击图片,也只有 UITapGestureRecognizerUITextView 关联的方法被执行。

以下是我实现的代码:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com