iOS小知识(2016.07)—iOS frame、bounds、anchorPoint、position以及transform

iOS frame、bounds、anchorPoint、position以及transform(全文)

1 frame

layer相对其父坐标系的位置。包括矩形左上角点,矩形宽高。值得注意的是layer被旋转后的宽高。如下图所示,bounds是40*50,frame是62*64。

2 bounds

layer相对其内部坐标系的位置。

3 anchorPoint

layer的锚点(默认是{0.5, 0.5},即在layer的中部)相对其内部单位坐标系的位置。锚点就是layer旋转的中点。左上角是{0, 0},右下角是{1,1}。值得注意的是锚点的值可以比0小,比1大,例如{-0.5, 1.5},如此layer旋转可以围绕外部某个点

4 position

layer的锚点相对其外部坐标系的位置。

5 transform (3D变换)

6 CALayer的frame决定因素

view或者layer的frame其实不是一个独立的属性,它是由bounds、position和transform决定的虚拟属性。因此,一旦以上3个属性发生变化frame就会变化。相反地,一旦改变frame,那么bounds、position和transform也可能变化。

The frame is not really a distinct property of the view or layer at all; it is a virtual property, computed from the bounds, position, and transform, and therefore changes when any of those properties are modified. Conversely, changing the frame may affect any or all of those values, as well.

7 参考文档

Core Animation Programming Guide

《iOS Core Animation Advanced Techniques》

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容