tap gesture not recognized on uiimageview(在 uiimageview 上无法识别点击手势)
问题描述
我添加了两个 uiimageview,一个在另一个 subview uiview 上(imageview1,imageview2).在第一个视图中,顶部 uiimageview 被隐藏(imageview2),而在第二个视图中,底部 imageview 被隐藏(imageview1代码>).
I added two uiimageviews, 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 上无法识别点击手势
基础教程推荐
- 如何从 logcat 中删除旧数据? 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
