如何获得转换后的CALayer的实际大小? [英] How to get the actual size of transformed CALayer?

查看:105
本文介绍了如何获得转换后的CALayer的实际大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 200x200像素 CALayer 实例,我对其进行了两次转换:

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


  • 缩小到50%

  • 应用了3D透视

现在我想将转换后的图层与另一个图层对齐。为此,我需要转换后的图层的大小(宽度和高度)。

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.

问题是 layer.bounds 仍返回该图层的 200x200 ,但由于透视变换,实际可见宽度较小,而高度大于 200 。顺便说一句,表示层的边界返回 0

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.

有什么方法可以确定转换后的 CALayer 的确切尺寸与在屏幕上绘制的完全一样?

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

谢谢,马克。

推荐答案

最后弄清楚了:边界在应用转换时保持不变,但是更改是图层的 frame 属性。

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

解决方案是使用 layer.frame.size 而不是 layer.bounds.size

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

核心动画中提到了这一点编程指南:

This is mentioned in the Core Animation Programming Guide:


图层具有一个隐式框架,该框架是位置,边界,anchorPoint和transform属性的函数。

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

这篇关于如何获得转换后的CALayer的实际大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆