Frame,Bounds的区别,center属性

来源:互联网 发布:淘宝人生无弹窗 编辑:程序博客网 时间:2024/05/16 18:15

Frame和Bounds的区别,很有用 - 战狼 - 战狼
Which to use?
-Usually depends on the context

If you are using a view, typically you use frame
If you are implementing a view, typically you use bounds
Matter of perspective
-From outside it's usually the frame
-From inside it's usually the bounds

Examples;
-Creating a view, positioning a view in superview - use frame

-Handing events, drawing a view - use bounds

frame指的是:该view在父view坐标系统中的位置和大小。(参照点是父亲的坐标系统)

bounds指的是:该view在本身坐标系统中 的位置和大小。(参照点是本身坐标系统


view 的bounds可以用来帮助它的subview来定位的


frame 如果一个按钮,是在表格里,按钮的frame 的坐标也是相对的,并不是相对屏幕,也就是说是相对坐标,不是绝对坐标


frame 是相对坐标。bounds是绝对坐标。


center属性包含了在父视图坐标系统中的已知中心点。

作用:主要使用center和frame属性来控制当前视图的几何结构

提示:当在运行时构建你的视图层次或者改变视图的尺寸或者位置时你可以使用这些属性。如果你只是要改变视图的位置,那么推荐使用center属性。center属性的值永远是可用的,即使添加了放缩或者转换因子到视图的转换矩阵当中。但是对于frame属性却不是,当视图的转换矩形不等于原始矩阵时它被当作时无效的。


三者关系:

即使你可以独立的改变frame,bounds和center属性,其中一个改变还是会影响到另外两个属性: