开发者

How to get the actual size of transformed CALayer?

开发者 https://www.devze.com 2023-02-22 01:53 出处:网络
I have a 200x200 pixel CALayer instance to which I\'ve applied two transformations: scaled开发者_运维技巧 down to 50%

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

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消