iOS学习笔记:关于center,frame,bounds,position,anchorPoint

frame:在父视图或父layer中的绝对坐标,修改它将会影响显示的位置和大小
bounds:可以看做是一个内部坐标,改变它可以整体改变subViews或者subLayer的显示位置和大小
center:当前视图的中心点在父视图上的坐标位置
position:当前layer的锚点在父layer上的坐标位置
anchorPoint:又一个采用单位坐标的属性,比较抽象,主要在动画场景使用比较多

position是layer中的anchorPoint点在superLayer中的位置坐标。因此可以说, position点是相对suerLayer的,anchorPoint点是相对layer的,两者是相对不同的坐标空间的一个重合点。

借用一篇博客中的公式

1
2
frame.origin.x = position.x - anchorPoint.x * bounds.size.width;  
frame.origin.y = position.y - anchorPoint.y * bounds.size.height;

彻底理解position与anchorPoint

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注