Search code examples
iosuiviewcore-animation

CALayer rotation appears to 'lift' it's child above the surface


Here is the iPad Simulator with four nested UIViews, drawing a custom background, and an inner UILabel. I am rotating the top UIView's CALayer, by getting it's layer and setting transform with a rotateY CATransform3D, animated on a separate thread (but the changes to transform are being sent on the main thread, naturally):

Oh deary me

Note- this animation does not loop correctly, hence it appears to bounce.

The layers do animate as a whole, but curiously, the first child and it's descendants appear to be floating above the UIView with the transform applied!

The UIViews themselves are children in another UIView, which has a red background. There are no other transformations being applied anywhere else.

The positions for each UIView were set using setFrame initially at the start.

What is causing this strange behaviour, and how can I ensure the child UIViews transform with their parent, giving a flat appearance to the surface as a whole?


Solution

  • Well. Perhaps unsurprisingly I was doing something silly, but since I'd not used CALayer transforms before, I didn't know if things were acting up. I had overridden layoutSubviews on the UIViews I was creating, and the act of rotating the CALayer was triggering this call and then pushing the child components frame around, due to a bug.