何时使用绑定和何时使用框架 [英] When to Use Bound and When to use Frame
问题描述
我发现
UIView的边界是矩形,表示为相对于位置(x,y)和大小
UIView的框架是矩形,表示为位置(x,y)和大小(宽度,高度)相对于它包含在其中的超级视图。
但我的怀疑是在哪种情况下,我将有边界被使用。我们在
中使用框架吗?是否需要使用绑定?
从查看编程指南:
- frame 属性包含框架矩形,用于指定视图在其超视角坐标系中的大小和位置。
- bounds 属性包含边界矩形,用于指定视图自身局部坐标系中视图的大小(及其内容起点)。
框架:
您使用中心和框架属性主要用于操作
当前视图的几何。例如,在构建视图层次结构时使用这些属性
,或在运行时更改
a视图的位置或大小。如果你只改变视图
(而不是它的大小)的位置,中心属性是首选方式。
中心属性中的值始终有效,即使缩放或
旋转因子已添加到视图的变换。同样的是
对于frame属性中的值不是真的,如果视图的变换不等于标识
变换,则认为
无效。
边界:
矩形在视图自身的局部坐标系中表示。该矩形的
默认原点是(0,0),其大小与框架矩形的
大小相匹配。任何你在这个矩形内绘制
是视图的可见内容的一部分。如果你改变
边界矩形的原点,你在新矩形中绘制的任何东西都会成为视图可见内容的
部分。
因此,您可以使用框架执行以下操作:
- 调整视图大小
- 移动/重新定位视图
您应该使用 / p> I have found out that The bounds of an UIView is the rectangle, expressed as a location (x,y) and size (width,height) relative to its own coordinate system (0,0). The frame of an UIView is the rectangle, expressed as a location (x,y) and size (width,height) relative to the superview it is contained within. But my doubt is in which scenario I will have the bounds to be used . Cant we use frames in all the cases ? Is there a need to use the bound ? From the View Programming Guide: Frame: You use the center and frame properties primarily for manipulating the
geometry of the current view. For example, you use these properties
when building your view hierarchy or changing the position or size of
a view at runtime. If you are changing only the position of the view
(and not its size), the center property is the preferred way to do so.
The value in the center property is always valid, even if scaling or
rotation factors have been added to the view’s transform. The same is
not true for the value in the frame property, which is considered
invalid if the view’s transform is not equal to the identity
transform. Bounds: You use the bounds property primarily during drawing. The bounds
rectangle is expressed in the view’s own local coordinate system. The
default origin of this rectangle is (0, 0) and its size matches the
size of the frame rectangle. Anything you draw inside this rectangle
is part of the view’s visible content. If you change the origin of the
bounds rectangle, anything you draw inside the new rectangle becomes
part of the view’s visible content. So you do the following things with the frame: Situation when you should use bounds: 这篇关于何时使用绑定和何时使用框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
drawRect:方法
UIView
中。
drawRect:
method of UIView
.