UIView *yellowView = [[UIView alloc] initWithFrame:CGRectMake(30, 30, 200, 200)];
yellowView.backgroundColor = [UIColor yellowColor];
[self.window addSubview:yellowView];
UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
redView.backgroundColor = [UIColor redColor];
//[self.window addSubview:redView];
[yellowView addSubview:redView];
第一步设置
yellowView.bounds = CGRectMake(0, 0, 200, 200);
//这表示yellowView在屏幕中的位置和大小不变,yellowView的左上角的相对于与其子视图为(0,0)
第二步设置
yellowView.bounds = CGRectMake(50, 50, 200, 200);
这表示yellowView在屏幕中的位置和大小不变,yellowView的左上角的相对于与其子视图为(50,50)
//位置如下,黄色视图的位置始终不变,bounds的x,y改变的是子视图相对于它的位置