layer.zPosition 不适用于非同级 UIView

发布于 2024-10-27 09:26:26 字数 403 浏览 4 评论 0原文

我有一个相当复杂的 UIImageView 层次结构。最初,当一个 UIImageView 移动到另一个 UIImageView 前面时,我小心地交换了同级顺序。然后我发现了 myUIImageView.layer.zPosition 并改用它。解决起来简单多了。它甚至几乎一直有效。我从这个SO问题中发现zPosition仅适用于同级层之间。伟大的!所以我真的有两个问题:是否有关于此的实际文档?而且,我可以用某种软糖来让它发挥作用吗? (就像将我所有的 UIImageView 添加到一个永远不可见的 UIView 中一样)。提前谢谢。

I have a reasonably complex hierarchy of UIImageViews. Originally, I was carefully swapping the sibling order when one UIImageView moved in front of another. Then I found out about myUIImageView.layer.zPosition and switched to using this instead. Worked out much simpler. It even works almost all the time. I found out from this SO question that zPosition only works amongst sibling layers. Great! So I have two questions really: Is there any actual documentation about this? and, is there some kind of fudge I can use to get this to work? (like adding all my UIImageViews to a UIView that is never visible). Thx in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情徒 2024-11-03 09:26:26

从您的问题标题来看,我想知道您是否理解 zPosition 属性适用于同级图层,而不是同级视图。要使用 zPosition 属性处理每个图像的深度,您需要将所有图像作为同级图层放在一个 UIView 对象中。 zPosition 属性记录在 Apple 的 核心动画编程指南

zPosition 属性指定图层位置的 z 轴分量。 zPosition 旨在用于设置图层相对于其同级图层的视觉位置。它不应该用于指定同级图层的顺序,而是在子图层数组中重新排序图层。

From the title of your question, I wonder if you understand that the zPosition property works with sibling layers, not sibling views. To deal with the depth of every image you have with the zPosition property, you will need to have all the images as sibling layers within one single UIView object. The zPosition property is documented in Apple's Core Animation Programming Guide:

The zPosition property specifies the z-axis component of the layer's position. The zPosition is intended to be used to set the visual position of the layer relative to its sibling layers. It should not be used to specify the order of layer siblings, instead reorder the layer in the sublayer array.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文