问题描述
我添加了两个 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 上无法识别点击手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!