0

I have an imageview in my scrollview,and i add a tap gesture for my uiscrollview. enter image description here

only the imageview area can respond tap gesture.

why when i set the backgroudcolor property of scrollview,then the whole scrollview can respond tap gesture。</p>

here is my code。</p>

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

2 回答 2

2

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

于 2013-05-09T05:01:24.427 回答
1

确保 UIImageView 上的 userInteractionEnabled 设置为 YES:

frame.userInteractionEnabled = YES;
于 2013-05-09T04:40:02.097 回答