// animatable. do not use frame if view is transformed since it will not correctly reflect the actual location of the view. use bounds + center instead.
@property(nonatomic) CGRect frame;
@property(nonatomic) CGRect bounds; // default bounds is zero origin, frame size. animatable
-(CGRect)frame{
return CGRectMake(self.frame.origin.x,self.frame.origin.y,self.frame.size.width,self.frame.size.height);
}
-(CGRect)bounds{
return CGRectMake(0,0,self.frame.size.width,self.frame.size.height);
}
1、bounds的原点是(0,0)点,是view本身的坐标系统,默认永远都是0,0点。
2、人为setbounds会改变其值,这时候就指定了自身view的起始点坐标为自身view的坐标系统的坐标值,eg:
[view1 setBounds:CGRectMake(-10, -10, 200 ,200)];这时候说明view的起点左边为(-10,-10)
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[view1 addSubview:view2];
把view2添加到view1上,此时view1坐标系左上角起点为(-10,-10)],所有view2会相对于view1向右向下各偏移10个点
3、frame的原点是任意的,它的原点是相对于父视图中的坐标位置。
本文详细解析了iOS和Android平台下视图坐标系统的特点,包括原点定义、bounds与frame属性的区别,以及如何通过bounds和frame正确定位视图元素。通过实例演示了如何设置视图坐标,实现不同设备间的兼容性调整。
991

被折叠的 条评论
为什么被折叠?



