理解frame、bounds、center、position、anchorPoint
来源:互联网 发布:win7数据库安装失败 编辑:程序博客网 时间:2024/06/09 15:34
UIView有三个比较重要的布局属性:frame
,bounds
和center
,CALayer
对应地叫做frame
,bounds
和position
。为了能清楚区分,图层用了“position”,视图用了“center”,但是他们都代表同样的值。
frame:描述当前界面元素在其父界面元素中的位置和大小。
bounds:描述当前界面元素在其自身坐标系统中的位置和大小。
center:描述当前界面元素的中心点在其父界面元素中的位置,图层用了“position”,视图用了“center”,但是他们都代表同样的值。一般我们可以通过以下公式得出center:
center.x = frame.origin.x + frame.size.width * 0.5;
center.y = frame.origin.y + frame.size.height * 0.5;
position是layer相对superLayer坐标空间的位置,很显然,这里的位置是根据anchorPoint来确定的。 至于如何确定,请看下面的公式:
position.x = frame.origin.x + anchorPoint.x * bounds.size.width;
position.y = frame.origin.y + anchorPoint.y * bounds.size.height;
UIView
和CALayer
的坐标系
视图的frame,bounds和center属性仅仅是储方法,当操纵frame,实际上改变位下视图下CAlayer的frame,不能独立于图层外改变视图的frame.
对于视图或者图层来说,frame
并不是一个非常清晰的属性,它其实是一个虚拟属性,是根据bounds
,position
和transform
计算而来,所以当其中任何一个值发生改变,frame都会变化。相反,改变frame的值同样会影响到他们当中的值。
anchorPoint(锚点)是用来移动图层的把柄,如把一张A4白纸用图钉订在书桌上,如果订得不是很紧的话,白纸就可以沿顺时针或逆时针方向围绕图钉旋转,这时候图钉就起着支点的作用。我们要解释的anchorPoint就相当于白纸上的图钉,它主要的作用就是用来作为变换的支点,旋转就是一种变换,类似的还有平移、缩放。
anchorPoint
位于图层的中点,所以图层的将会以这个点为中心放置。
总结
1、position是layer中的anchorPoint在superLayer中的位置坐标。
2、互不影响原则:单独修改position与anchorPoint中任何一个属性都不影响另一个属性。
3、frame、position与anchorPoint有以下关系:
frame.origin.x = position.x - anchorPoint.x * bounds.size.width;
frame.origin.y = position.y - anchorPoint.y * bounds.size.height;
第2条的互不影响原则还可以这样理解:position与anchorPoint是处于不同坐标空间中的重合点,修改重合点在一个坐标空间的位置不影响该重合点在另一个坐标空间中的位置。
- 理解frame、bounds、center、position、anchorPoint
- frame、bounds、center、anchorPoint、position
- position与frame bounds anchorPoint的深入理解
- ios CALayer的Frame,bounds,position,anchorPoint
- anchorPoint,position,frame 深刻理解
- uiview frame,bounds,center 理解
- uiview frame,bounds,center 理解
- 图层的frame、bounds、position和anchorPoint关系
- frame、bounds、center
- frame.bounds和center
- frame | center |bounds |transform
- frame、bounds和center
- frame bounds center
- frame,bounds和center
- frame、bounds、center
- frame.center和bounds
- iOS项目开发实战——理解frame,bounds,center
- frame、bounds、center的区别
- 通过代码关闭程序
- TCP发送接口(如send(),write()等)的返回值与成功发送到接收端的数据量无直接关系 .
- PLSQL性能优化方法
- php综合面试题
- Java获取计算机的名称、IP、环境变量的配置信息
- 理解frame、bounds、center、position、anchorPoint
- poj 1753--Flip Game
- druid简单详解
- Arraylist 逆置,循环右移,循环左移
- 回文词
- Flip Game
- ubuntu: Unable to correct problems, you have held broken packages 解决方案
- VS2013生成DLL却没有lib文件
- js和jstl标签混用,太强大了!