2013-05-09 84 views
0

我在我的scrollview中有一个imageview,并且为我的uiscrollview添加了一个水龙头手势。 enter image description here关于uiscrollview中的水龙头手势

只有imageview区域可以响应轻击手势。

为什么当我设置滚动型的backgroudcolor财产,那么整个滚动视图可以响应双击手势

这里是我的代码

UIImageView * imgview=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bizhi1.png"]];  
imgview.frame=CGRectMake(0, 140, 320, 200);  

UIScrollView * scrollview=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 
[scrollview addSubview:imgview]; 

//when i set the backgroudcolor,then the whole scrollview can respond tap gesture 
//scrollview.layer.backgroundColor=[UIColor redColor].CGColor; 

//add a TapGesture for scrollview 
UITapGestureRecognizer * tapGesture=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SwitchTabBarHidden)];  
[scrollview addGestureRecognizer:tapGesture]; 
[tapGesture release]; 

[imgview release]; 
[self.view addSubview:scrollview]; 
[scrollview release]; 
+1

你想只在两个图像视图的手势? – 2013-05-09 04:38:49

+0

只是想整个uiscrollview区域可以响应轻击手势。 – 2013-05-09 04:47:55

+0

请获取触摸位置坐标 - (void)singleTapGestureCaptured :(UITapGestureRecognizer *)手势 – Deepesh 2013-05-09 04:48:03

回答

2

我敢肯定,这个代码是正确的,因为我实现了这个代码,并没有必要设置的backgroundColor财产滚动视图。

+0

好吧,我打算为这个测试创建一个新项目。 – 2013-05-09 05:06:47

+0

你确定你可以...... – 2013-05-09 05:11:39

+0

发生了什么我亲爱的你有吗? – 2013-05-09 05:20:21

1

确保userInteractionEnabled设置为YES上的UIImageView。:

frame.userInteractionEnabled = YES; 
+0

嗨! Rushabh。即使我添加imgview.userInteractionEnabled = YES;,它仍然只有imageview区域可以响应轻击手势。 – 2013-05-09 04:45:56