iOS开发-frame与bounds
frame: 描述view在super的坐标系的位置与大小;
bounds: 描述view在自己的坐标系的位置与大小;
1、frame
修改frame的值,会对应改变center和bounds的值;如果设置了view的transform属性不为CGAffineTransformIdentity,那么frame的属性不确定;
修改frame的值,会自动重绘,并且不调用drawRect函数。如果需要调用drawRect函数,可以把contentMode property 设置为 UIViewContentModeRedraw.
修改frame的值可以产生动画(在动画block内),但是如果设置了view的transform属性不为CGAffineTransformIdentity,那么frame的属性不确定,不应该修改。此时可以通过修改center和bounds的属性来替代。
2、bounds
origin默认值是(0,0),size和frame的size是耦合的,修改其中的一个会影响另外一个;
修改bounds的size大小,会根据center放大或者收缩。
修改bounds的值,会自动重绘,并且不调用drawRect函数。如果需要调用drawRect函数,可以把contentMode property 设置为 UIViewContentModeRedraw.
frame:
The frame rectangle, which describes the view’s location and size in its superview’s coordinate system. This rectangle defines the size and position of the view in its superview’s coordinate system. You use this rectangle during layout operations to size and position the view. Setting this property changes the point specified by the center property and the size in the bounds rectangle accordingly. The coordinates of the frame rectangle are always specified in points. Warning:Warning If the transform property is not the identity transform, the value of this property is undefined and therefore should be ignored. Changing the frame rectangle automatically redisplays the receiver without invoking the drawRect: method. If you want the drawRect: method invoked when the frame rectangle changes, set the contentMode property to UIViewContentModeRedraw. Changes to this property can be animated. However, if the transform property contains a non-identity transform, the value of the frame property is undefined and should not be modified. In that case, you can reposition the view using the center property and adjust the size using the bounds property instead.
bounds:
The bounds rectangle, which describes the view’s location and size in its own coordinate system. On the screen, the bounds rectangle represents the same visible portion of the view as its frame rectangle. By default, the origin of the bounds rectangle is set to (0, 0) but you can change this value to display different portions of the view. The size of the bounds rectangle is coupled to the size of the frame rectangle, so that changes to one affect the other. Changing the bounds size grows or shrinks the view relative to its center point. The coordinates of the bounds rectangle are always specified in points. Changing the frame rectangle automatically redisplays the receiver without invoking the drawRect: method. If you want the drawRect: method invoked when the frame rectangle changes, set the contentMode property to UIViewContentModeRedraw. Changes to this property can be animated. The default bounds origin is (0,0) and the size is the same as the frame rectangle’s size.
扩展