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

2024-01-06

这是我的代码......

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

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


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

当谈到 ZPosition 时,它变得有些有趣..将 ZPosition 更改为更高的值使视图可见,而无需对索引位置进行任何更改..因此在这种情况下,索引零上的子视图也可能完全可见,但事实并非如此。这并不意味着它将接收所有触摸,因为它仍然位于零索引上......如果您想让零索引子视图接收所有触摸,则使用 UIView 类的方法将其置于其他子视图之上。 ...
不要同时使用手势和 ZPosition,它可能会在与您的应用交互时让用户感到困惑。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将手势传递给视图在 z 轴上的排列 的相关文章

随机推荐