将手势传递到视图在z轴上的排列

bha*_*esh 2 cocoa-touch ios

这是我的代码....

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];
Run Code Online (Sandbox Code Playgroud)

我想让视图只识别代码中添加的单个手势,并将其他手势传递给下面的视图....
如何实现此功能?

bha*_*esh 5

这个问题非常容易回答.....
当谈到在ios中识别Gesture时,最顶层的视图总是会收到用户的触摸,因此手势识别取决于子视图的堆叠方式意味着它在SuperView属性中的排列方式命名子视图....如果多个子视图保持屏幕的相同接触点,则子视图中具有较高索引值的视图将获得触摸...通常具有较高索引值的视图也将在其他视图之上可见....

当涉及到ZPosition时,它会使一些有趣的事情.将ZPosition更改为更高的值使得视图可见而不会对索引位置进行任何更改.因此,在这种情况下,索引零上的子视图也可能完全可见,但它不会t意味着它将接收所有的触摸,因为它仍然在零索引.....如果你想让零索引子视图接收所有的触摸,那么使用UIView类的方法将它置于其他人之上. ...
不要一起使用Gesture和ZPosition,它可能会在与您的应用程序交互时混淆用户.

  • 这个答案对我很有帮助.我通过更改zPosition使我的视图可见,但他们没有收到任何接触.现在我使用`[self.view bringViewToFront:subview]`,一切正常! (2认同)