简体   繁体   English

关于uiscrollview中的点击手势

[英]About tap gesture in uiscrollview

I have an imageview in my scrollview,and i add a tap gesture for my uiscrollview. 我的滚动视图中有一个imageview,并且为uiscrollview添加了轻按手势。 在此处输入图片说明

only the imageview area can respond tap gesture. 只有imageview区域可以响应轻击手势。

why when i set the backgroudcolor property of scrollview,then the whole scrollview can respond tap gesture。 为什么当我设置滚动视图的backgroudcolor属性时,整个滚动视图才能响应轻击手势。

here is my code。 这是我的代码。

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];

我确定这段代码是正确的,因为我已经实现了这段代码,不需要设置scrollview的backgroundColor属性。

确保在UIImageView上将userInteractionEnabled设置为YES:

frame.userInteractionEnabled = YES;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM