0
votes

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。

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];
2
You wanna gesture on only both image view ?Dharmbir Singh
just want the whole uiscrollview area can respond the tap gesture.Rock_Choke
please get touch location coordinate - (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gestureDeepesh
you sure that you will get toouch in scrollview or not ?Deepesh
This code is working proper at my end. I think you are doing something wrong in other code.Dharmbir Singh

2 Answers

2
votes

I'm sure this code is correct because i've implemented this code and there is no need to set the backgroundColor property of scrollview.

1
votes

Make sure userInteractionEnabled is set to YES on the UIImageView:

frame.userInteractionEnabled = YES;