iPhone - 如何捕捉 UIWebView 或 UIImageView 的点击

发布于 2024-11-03 04:05:07 字数 619 浏览 2 评论 0原文

我有一个像这样生成的视图:

oneView = [[UIView alloc] initWithFrame:CGRectMake(x, y , w, h)];
oneView.tag = i;

UITapGestureRecognizer* recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap2:)];
[recognizer setNumberOfTouchesRequired:1];
[oneView addGestureRecognizer:recognizer];
recognizer.delegate = self;
[recognizer release];

- (void)handleSingleTap2:(UITapGestureRecognizer *)recognizer {
    int viewID = recognizer.view.tag;
    NSLog(@"id : %d", viewID);
}

这有效,但是如果我用 UIWebView 或 UIImageView 分配替换 UIView 分配,则不再触发触摸事件。

我怎样才能让它发挥作用?

I have a View generated like this :

oneView = [[UIView alloc] initWithFrame:CGRectMake(x, y , w, h)];
oneView.tag = i;

UITapGestureRecognizer* recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap2:)];
[recognizer setNumberOfTouchesRequired:1];
[oneView addGestureRecognizer:recognizer];
recognizer.delegate = self;
[recognizer release];

- (void)handleSingleTap2:(UITapGestureRecognizer *)recognizer {
    int viewID = recognizer.view.tag;
    NSLog(@"id : %d", viewID);
}

This works, but if I replace the UIView alloc with a UIWebView or UIImageView alloc, then touch event is not triggerred anymore.

How may I make it work ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

掀纱窥君容 2024-11-10 04:05:07

设置 userInteractionEnabled=YES 并且如果需要 multipleTouchEnabled=YES

set userInteractionEnabled=YES and if needed multipleTouchEnabled=YES

兲鉂ぱ嘚淚 2024-11-10 04:05:07

关于您关于UIWebView的问题,我建议您看看drawnonward的答案:

UIGestureRecognizer 在 UIWebView 上工作吗?

对于 UIImageView 部分,请参阅此教程:

UIImageView-with-zooming-tapping

我无法将代码粘贴到此处,但我认为这将使该区域保持干净且更易于操作阅读。

Regarding your question about the UIWebView I suggest you have a look at drawnonward's Answer :

Does UIGestureRecognizer work on a UIWebView?

And for the UIImageView Part see this Tutorial:

UIImageView-with-zooming-tapping

I could not paste the code here but i think this will keep this area cleaner and easier to read.

坐在坟头思考人生 2024-11-10 04:05:07

您必须重写

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;

委托函数并返回 YES;

you must override

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;

delegate function and return YES;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文