本文介绍了layer.zPosition 不适用于非同级 UIView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当复杂的 UIImageView 层次结构.最初,当一个 UIImageView 移到另一个前面时,我小心地交换了兄弟顺序.然后我发现了 myUIImageView.layer.zPosition 并改用它.解决起来简单多了.它甚至几乎一直有效.我从 this SO question 发现 zPosition仅适用于兄弟层.伟大的!所以我真的有两个问题:是否有任何关于此的实际文档?而且,我可以用某种软糖来让它发挥作用吗?(比如将我所有的 UIImageViews 添加到一个永远不可见的 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.

推荐答案

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

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:

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

这篇关于layer.zPosition 不适用于非同级 UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-03 02:54