Search code examples
iosobjective-ccocoa-touchuiviewcatransform3d

Why does a transformed UIView overlap other views that are higher in the hierarchy?


I have a view to whose layer I applied transformations - altered the m34 field, rotated it on the x axis and scaled it on x and y. Then I added this view to a bigger superview. My issue is that every other view I add to the bigger superview gets hidden or overlapped by the transformed one (if the new view's frame intersects the transformed view's frame), even though the new views stand higher in the hierarchy than the transformed one and those new views get added to the end of the subviews array of the bigger superview. Any ideas what is the reason behind this behavior? :-) Thanks a lot!


Solution

  • 3D transformations are used to make pseudo-3D. And in this 3D space your layer overlaps others. To change its z-pozition use CAlayer's property

    @property CGFloat zPosition;
    

    The layer’s position on the z axis. Animatable. The default value of this property is 0. Changing the value of this property changes the the front-to-back ordering of layers onscreen. This can affect the visibility of layers whose frame rectangles overlap. The value of this property is measured in points.