区别:
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];
这时显示的视图是
时间: 2024-11-08 12:16:57