layer.zPosition不适用于非同级UIViews [英] layer.zPosition does not work with non-sibling UIViews

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

问题描述

我有一个相当复杂的层次结构 UIImageView s。最初,当一个 UIImageView 在另一个前面移动时,我仔细地交换了兄弟姐妹顺序。然后我发现了关于 myUIImageView.layer.zPosition 并切换到使用它。工作更简单。它甚至可以在任何时候使用几乎。我从这个SO问题发现 zPosition 只能在兄弟层中使用。大!所以我真的有两个问题:有没有关于这个的实际文档?而且,有没有什么可以用来让这个工作起作用的软糖? (比如将所有的UIImageView添加到永不可见的UIView中)。 Thx在提前。

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 属性可以与兄弟图层一起使用,而不是同级视图。要使用 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旨在用于设置图层相对于其兄弟图层的视觉位置。它不应该用于指定层同胞的顺序,而是重新排列子层数组中的图层。

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.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆