0

Louis - Thanks for your input. Here is what I did, and my current issues, which i don't understand.

The menus (2) are UIImageViews that respond to touch. Each is it's own class. The 'sprites' as you called them also respond to touch.

In the .m where I add the menus and sprites to the layer, I created two container layers, via this code: menuContainer = [CALayer layer].

I ordered them with the menuContainer above the spriteContainer. Now, the sprites do move below the menus - great! But in the process, the sprites stopped responding to touch (I can understand this as they are below the menuContainer layer), and the menus stopped responding to touch as well (don't get that). Continuing to confuse the situation, a layer added to the menuContainer that responds to a multitouch gesture by popping up a slider still reads the multitouch and pops up the slider, but I can't slide the slider. This has me thoroughly confounded.

Thanks.

My app is building a background layer, then building some menu layers that should always be at the top. After this, I add many moving layers and remove many moving layers very quickly.

My problem is I want my menu layers (there are 4) to always be in front of the other layers. I have thought of building a layer hiearchy and using the insertsublayer: atindex: method, making my menus a notional index of 1000, and inserting the multitude of moving layers at a lower index, like 200. If I insert one layer at 200 and then the next at 200, does the first layer that was assigned to 200 get shifted (to 201) or does it get blown away?

I have tried inserting the layers with the insertsublayer: below:, but that does not give me the desired results.

Thanks for the help.

4

2 回答 2

2

你真的不能那样做,层索引不是z-order,它是一个数组索引。从文档中:

此值不得大于子层数组中的元素计数。

我认为你会得到最好的服务,但实际上是建立一个真正的层级结构,而不是试图将所有活动层推到一个超级层中。在其他方面,但将所有菜单层放入容器层中,然后将其插入到您想要的根层中。同样,将所有精灵插入一个容器层,并将其放在您想要的根层中。

基于您的编辑的其他内容:

层本质上是一种图形结构,它们不直接响应事件。您要么需要自己处理,通过编写代码在它们附加到的视图中对它们进行 hitTest,或者你需要使用 UIViews 而不是层。您之前可能已经摆脱了它,因为您以视图层次结构和层层次结构一致的方式操作图层,但是从您最初的问题中我不清楚您使用的是视图而不是纯粹基于图层设置。

于 2009-11-17T23:59:02.990 回答
-1

路易斯 - 感谢您的意见。这是我所做的,以及我目前不明白的问题。

菜单 (2) 是响应触摸的 UIImageView。每个都是它自己的类。你所说的“精灵”也会对触摸做出反应。

在我将菜单和精灵添加到图层的 .m 中,我通过以下代码创建了两个容器层:menuContainer = [CALayer layer]。

我用 spriteContainer 上方的 menuContainer 订购了它们。现在,精灵确实在菜单下方移动 - 太棒了!但是在这个过程中,精灵停止响应触摸(我可以理解,因为它们位于 menuContainer 层之下),并且菜单也停止响应触摸(不明白)。继续混淆情况,添加到 menuContainer 的层通过弹出滑块响应多点触控手势仍然读取多点触控并弹出滑块,但我无法滑动滑块。这让我彻底困惑。

谢谢。

于 2009-11-18T04:58:36.010 回答