tap gesture not recognized on uiimageview(在 uiimageview 上无法识别点击手势)
问题描述
我添加了两个 uiimageview
,一个在另一个 subview uiview
上(imageview1,imageview2
).在第一个视图中,顶部 uiimageview
被隐藏(imageview2
),而在第二个视图中,底部 imageview
被隐藏(imageview1代码>).
I added two uiimageview
s, one on another subview uiview
(imageview1,imageview2
). In the first view the top uiimageview
is hidden(imageview2
) and in the second view the bottom imageview
is hidden(imageview1
).
分配点击手势:
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(oneTap:)];
UITapGestureRecognizer *singleTap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(oneTap:)];
将两个 uiimageview 的用户交互设置为 YES.
Set user interaction for both uiimageview to YES.
[singleTap setNumberOfTapsRequired:1];
[singleTap1 setNumberOfTapsRequired:1];
//给uiimageview添加手势
// adding gesture to uiimageview
分别添加点击手势识别器和选择器.
Add tap gesture recognizer and selector respectively.
[imageview1 addGestureRecognizer:singleTap];
[imageview2 addGestureRecognizer:singleTap1];
但我的水龙头无法识别.
But my taps are not recognized.
谁能告诉我错在哪里?
推荐答案
在添加手势识别器之前尝试设置setUserInteractionEnabled:YES
.
Try setting setUserInteractionEnabled:YES
before adding gesture recognizer.
[imageview1 setUserInteractionEnabled:YES]
[imageview2 setUserInteractionEnabled:YES]
[imageview1 addGestureRecognizer:singleTap];
[imageview2 addGestureRecognizer:singleTap1];
更新:
在您发表评论后,我建议您在检测到点击事件之前将您的观点置于顶部.因为父 imageView 在上面并捕获了这些点击.
After the comment you have made I suggest you bring your views to the top before detecting the tap event. Because parent imageView is above and catches these taps.
[yourparentview bringSubviewToFront:imageview1];
[yourparentview bringSubviewToFront:imageview2];
这篇关于在 uiimageview 上无法识别点击手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 uiimageview 上无法识别点击手势
基础教程推荐
- Android:对话框关闭而不调用关闭 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01