我添加了两个uiimageview
,一个在另一个subview uiview
(imageview1,imageview2
)上。在第一个视图中,顶部uiimageview
被隐藏(imageview2
),而在第二个视图中,底部imageview
被隐藏(imageview1
)。
分配点击手势:
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(oneTap:)];
UITapGestureRecognizer *singleTap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(oneTap:)];
将uiimageview的用户互动设置为YES。
[singleTap setNumberOfTapsRequired:1];
[singleTap1 setNumberOfTapsRequired:1];
//向uiimageview添加手势
分别添加点击手势识别器和选择器。
[imageview1 addGestureRecognizer:singleTap];
[imageview2 addGestureRecognizer:singleTap1];
但我的水龙头无法辨认。
任何人都能告诉我错误在哪里吗?
答案 0 :(得分:108)
在添加手势识别器之前尝试设置setUserInteractionEnabled:YES
。
[imageview1 setUserInteractionEnabled:YES]
[imageview2 setUserInteractionEnabled:YES]
[imageview1 addGestureRecognizer:singleTap];
[imageview2 addGestureRecognizer:singleTap1];
<强>更新强>
在您发表评论后,我建议您在检测到点击事件之前将您的观点置于顶部。因为父imageView在上面并且捕获了这些点击。
[yourparentview bringSubviewToFront:imageview1];
[yourparentview bringSubviewToFront:imageview2];
答案 1 :(得分:2)
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(oneTap:)];
singleTap.numberOfTapsRequired = 1;
singleTap.numberOfTouchesRequired = 1;
singleTap.delegate = self;
[imageview1 addGestureRecogniser:singleTap];
[singleTap1 release];
imageview1.userInteractionEnabled = YES; //disabled by default