首页 > 其他 > 详细

bounds和frame的区别?

时间:2016-04-22 18:18:42      阅读:235      评论:0      收藏:0      [点我收藏+]

frame和bounds都市用来描述一块区域的

frame是以父控件的左上角为原点,可视范围相对于父控件

bounds:描述是可视范围在内容哪个区域,相对于内容.

           可视化区域在内容中显示区域,bounds的x,y可以改(改的是内容原点的位置)

任何控件都有自己的内容,而且这个内容无限大

子控件都市相对于内容

 

UIView *redView = [[UIView alloc] init];

    redView.frame = CGRectMake(50, 50, 200, 200);

    redView.backgroundColor = [UIColor redColor];

    [self.view addSubview:redView];

    _redView = redView;

    

    UISwitch *switchV = [[UISwitch alloc] init];

    [_redView addSubview:switchV];

    // Do any additional setup after loading the view, typically from a nib.

}

 

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event

{

    CGRect bounds = _redView.bounds;

    bounds.origin.y += 10;

    _redView.bounds = bounds;

}

 

bounds和frame的区别?

原文:http://www.cnblogs.com/sanvow/p/5422224.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!