34

我加了两个uiimageviews,一个接一个subview uiviewimageview1,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];

但是我的水龙头无法识别。

谁能告诉我错误在哪里?

4

2 回答 2

113

setUserInteractionEnabled:YES在添加手势识别器之前尝试设置。

[imageview1 setUserInteractionEnabled:YES]
[imageview2 setUserInteractionEnabled:YES]

[imageview1 addGestureRecognizer:singleTap];
[imageview2 addGestureRecognizer:singleTap1];   

更新:

在您发表评论后,我建议您在检测到点击事件之前将您的观点置于顶部。因为父 imageView 在上面并捕获了这些点击。

[yourparentview bringSubviewToFront:imageview1];
[yourparentview bringSubviewToFront:imageview2];
于 2013-10-07T06:13:54.960 回答
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
于 2013-10-07T06:30:37.957 回答