3

Here is my code....

UIView *View1 = [[UIView alloc] initWithFrame:CGRectMake(0, 300, 1000, 150)];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(callTap)];
[View1 addGestureRecognizer:tap];
view1.userInteractionEnabled = true;
view1.layer.zPosition=1;
[self.view addSubview:view1];

UIView *View2 = [[UIView alloc] initWithFrame:CGRectMake(0, 300, 1000, 150)];
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(callPinch)];
[View2 addGestureRecognizer:pinch];
View2.userInteractionEnabled= true;
View2.layer.zPosition=2;
[self.view addSubview:View2];

UIView *View3 = [[UIView alloc] initWithFrame:CGRectMake(0, 300, 1000, 150)];
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(callPan)];
[View3 addGestureRecognizer:pan];
View3.userInteractionEnabled=true;
View3.layer.zPosition=3;
[self.view addSubview:View3];

I want to make the view recognize only single gesture as added in the code and pass other to the view below....
How to achieve this functionality?

bhawesh
  • 1,310
  • 2
  • 19
  • 57

1 Answers1

7

When it comes to recognizing Gesture in ios the topmost view always receive the touches of the user so gesture recognizing depends on how your subviews are stacked means how it is arranges in the SuperView's Property named subViews....if multiple subviews hold same touchpoint of the screen then the view with higher index value in subViews will get the touch..and generally view with higher index value will be visible on top of others too....

when it comes to the ZPosition it makes someWhat Interesting..Changing the ZPosition to a higher value makes the View visible without making any change in index position..so in this case subview on the index zero also might be visible completely but it doesn't mean it going to receive all the touches because it is still on the zero index.....if you want to make the zero index subview to receive all touches then use methods of UIView class to bring it on top of others.....
Don't use Gesture and ZPosition together, it might confuse users while interacting with your app.

bhawesh
  • 1,310
  • 2
  • 19
  • 57
  • 1
    Great answer. To clarify, the index value is set in interface builder. If you want a view to get the gesture events, move it down in the Objects hierarchy view. The lower the view in the list, the higher the index. A bit counter intuitive. view.layer.zPosition only affects the visibility and not gesture event dispatch. – RajV Sep 13 '13 at 19:24
  • 3
    This answer helped me alot. I made my views visible by changing the zPosition but they didn't receive any touches. Now I use `[self.view bringViewToFront:subview]` and everything works! – Marc Feb 25 '14 at 11:27