Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

iphone - layer.zPosition does not work with non-sibling UIViews

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...