1.在view1视图上以view1.frame的格式添加view2视图
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)];
view1.backgroundColor = [UIColor greenColor];
[self.window addSubview:view1];
UIView *view2 = [[UIView alloc] initWithFrame:view1.frame];
view2.backgroundColor = [UIColor redColor];
[view1 addSubview:view2];
解答:
①、view1的是将手机屏幕的左上角作为原点
②、view2则是将view1的左上角作为原点
③、可以理解为:view2以view1作为self.window,然后添加(view1就是view2的父视图)
④、在A视图上添加B视图,如果B以A的frame格式添加视图,就是以A作为self.window
2、在view1视图上一view1.brounds的格式添加视图
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)];
view1.backgroundColor = [UIColor greenColor];
[self.window addSubview:view1];
UIView *view2 = [[UIView alloc] initWithFrame:view1.bounds];
view2.backgroundColor = [UIColor redColor];
[view1 addSubview:view2];
解答:
①、此时view1和view2都是以屏幕的左上角作为原点
②、通俗点说就是view2是在view1视图上拷贝了view1,然后再view1所在的位置上黏贴了view2
③、个人认为view2将self.window的原点,添加
④、在A视图上添加B视图,若B视图是以A视图的bounds格式添加,此时B视图以self.window的原点,添加
3、在self.window视图上以view1.bounds格式添加view2
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(50, 0, 200, 200)];
view1.backgroundColor = [UIColor greenColor];
[self.window addSubview:view1];
UIView *view2 = [[UIView alloc] initWithFrame:view1.bounds];
view2.backgroundColor = [UIColor redColor];
[self.window addSubview:view2];
view2.alpha = 0.3;
解答:
①、此时的屏幕原本的原点有(0,0),改成了(-50,0);
②、也可以说是将view1的x坐标和y坐标取相反数作为self.window的原点
③、在self.window视图上,如果B视图以A视图的bounds格式添加,此时的self.window取A视图的X坐标和Y坐标的各自相反数作为自己的原点
4、在self.widow视图上一view1.frame格式添加view2
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(50, 0, 200, 200)];
view1.backgroundColor = [UIColor greenColor];
[self.window addSubview:view1];
UIView *view2 = [[UIView alloc] initWithFrame:view1.frame];
view2.backgroundColor = [UIColor redColor];
[self.window addSubview:view2];
view2.alpha = 0.3;
解答:
①、以view1的创建格式做为view2的格式添加view2
②、通俗说就是view2在view1的位置上拷贝了view1
③、在self.window视图上,以A视图的frame格式添加B视图,就是B视图在A视图的位置上拷贝了A视图且粘贴在A视图上
注:新手理解,高手请唔喷...