How to get the actual size of transformed CALayer?

懵懂的女人 提交于 2019-12-13 12:05:47

问题


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?

Thanks, Mark.


回答1:


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.



来源:https://stackoverflow.com/questions/5537586/how-to-get-the-actual-size-of-transformed-calayer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!