码迷,mamicode.com
首页 > 其他好文 > 详细

frame和bounds

时间:2016-06-01 22:45:11      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

区别:

frame:根据父视图坐标系来确定自己的位置
bounds:该视图在自己坐标系的位置和大小
            修改bounds并不会引起视图位置的变化,会影响自身子视图的位置;修改frame会引起视图位置的变化

UIView *view1 = [[UIView alloc] init];
view1.frame = CGRectMake(10, 10, 200, 200);
[self.wiew addSubview:view1];

UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
    view2.backgroundColor = [UIColor yellowColor];
    [view1 addSubview:view2];

这时显示的视图是

技术分享

UIView *view1 = [[UIView alloc] init];
view1.frame = CGRectMake(10, 10, 200, 200);
view1.bounds = CGRectMake(50, 50, 200, 200);
[self.wiew addSubview:view1];

UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
    view2.backgroundColor = [UIColor yellowColor];
    [view1 addSubview:view2];

这时显示的视图是

技术分享

frame和bounds

标签:

原文地址:http://www.cnblogs.com/menglingxu/p/5551158.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!