Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the actual size of transformed CALayer?

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

  • scaled down to 50%
  • applied a 3D perspective

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

The problem is that layer.bounds still returns 200x200 for the layer, but because of the perspective transformation the actual visible width is less and the height more than 200. The bounds of the presentation layer return 0, by the way.

Is there any way how I can determine the exact size of a transformed CALayer exactly as it is drawn on screen?

like image 780
Mark Avatar asked Apr 04 '11 11:04

Mark


1 Answers

Finally figured it out: the bounds remain unchanged when applying a transformation, but what changes is the layer's frame property.

Solution is to use layer.frame.size instead of layer.bounds.size.

This is mentioned in the Core Animation Programming Guide:

Layers have an implicit frame that is a function of the position, bounds, anchorPoint, and transform properties.

like image 176
Mark Avatar answered Oct 03 '22 10:10

Mark