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

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从您的问题标题来看,我想知道您是否理解
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 thezPosition
property, you will need to have all the images as sibling layers within one single UIView object. ThezPosition
property is documented in Apple's Core Animation Programming Guide: