How to get the actual size of the converted CALayer?

I have a 200x200 pixel CALayer to which I applied two transformations:

  • reduced to 50%
  • applied three-dimensional perspective

Now I want to align the transformed layer with another layer. To do this, I need the size (width and height) of the converted layer.

The problem is that layer.bounds still returns 200x200 for the layer, but due to perspective conversion, the actual visible width is smaller and the height is greater than 200 . View layer ratings return 0 , by the way.

Is there a way to determine the exact size of the converted CALayer exactly as it appears on the screen?

Thanks Mark.

+6
core-animation calayer catransform3d
source share
1 answer

Finally it turned out: bounds remain unchanged when applying the transform, but what changes are a property of the layer frame .

The solution is to use layer.frame.size instead of layer.bounds.size .

This is indicated in the main animation programming guide:

Layers have an implicit frame, which is a function of position, border, snap, and transform properties.

+11
source share

All Articles