如何获取转换后的CALayer的实际大小?
我有一个 200x200 像素
CALayer
实例,我对其应用了两次转换:
- 缩小到 50%
- 应用 3D 透视
现在我想将转换后的图层与另一图层对齐。为此,我需要转换后的图层的大小(宽度和高度)。
问题是,layer.bounds
仍然为图层返回 200x200
,但由于透视变换,实际可见宽度小于 200< /代码>。顺便说一句,表示层的边界返回
0
。
有什么方法可以确定转换后的 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后弄清楚了:应用变换时,边界保持不变,但改变的是图层的框架属性。
解决方案是使用
layer.frame.size
而不是layer.bounds.size
。核心动画编程指南中提到了这一点:
Finally figured it out: the
bounds
remain unchanged when applying a transformation, but what changes is the layer'sframe
property.Solution is to use
layer.frame.size
instead oflayer.bounds.size
.This is mentioned in the Core Animation Programming Guide: