bounds和frame的区别
来源:互联网 发布:mac如何压缩文件 编辑:程序博客网 时间:2024/06/08 21:04
1.在view1视图上以view1.frame的格式添加view2视图
UIView *view1 = [[UIViewalloc] initWithFrame:CGRectMake(50,50, 200, 200)];
view1.backgroundColor = [UIColorgreenColor];
[self.windowaddSubview:view1];
UIView *view2 = [[UIViewalloc] initWithFrame:view1.frame];
view2.backgroundColor = [UIColorredColor];
[view1addSubview:view2];
解答:
①、view1的是将手机屏幕的左上角作为原点
②、view2则是将view1的左上角作为原点
③、可以理解为:view2以view1作为self.window,然后添加(view1就是view2的父视图)
④、在A视图上添加B视图,如果B以A的frame格式添加视图,就是以A作为self.window
2、在view1视图上一view1.brounds的格式添加视图
UIView *view1 = [[UIViewalloc] initWithFrame:CGRectMake(50,50, 200, 200)];
view1.backgroundColor = [UIColorgreenColor];
[self.windowaddSubview:view1];
UIView *view2 = [[UIViewalloc] initWithFrame:view1.bounds];
view2.backgroundColor = [UIColorredColor];
[view1addSubview: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 = [[UIViewalloc] initWithFrame:CGRectMake(50,0, 200, 200)];
view1.backgroundColor = [UIColorgreenColor];
[self.windowaddSubview:view1];
UIView *view2 = [[UIViewalloc] initWithFrame:view1.bounds];
view2.backgroundColor = [UIColorredColor];
[self.windowaddSubview: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 = [[UIViewalloc] initWithFrame:CGRectMake(50,0, 200, 200)];
view1.backgroundColor = [UIColorgreenColor];
[self.windowaddSubview:view1];
UIView *view2 = [[UIViewalloc] initWithFrame:view1.frame];
view2.backgroundColor = [UIColorredColor];
[self.windowaddSubview:view2];
view2.alpha =0.3;
解答:
①、以view1的创建格式做为view2的格式添加view2
②、通俗说就是view2在view1的位置上拷贝了view1
③、在self.window视图上,以A视图的frame格式添加B视图,就是B视图在A视图的位置上拷贝了A视图且粘贴在A视图上
注:新手理解,高手请唔喷...
- frame 和bounds 的区别
- bounds和frame的区别
- frame和bounds的区别
- frame 和 bounds 的区别
- frame和bounds的区别
- frame和bounds的区别
- frame和bounds的区别
- frame和bounds的区别
- bounds和frame的区别
- frame和bounds的区别
- Bounds 和 Frame 的区别
- bounds和frame区别
- bounds和frame区别
- bounds和frame区别
- bounds 和frame区别
- frame 和 bounds 区别
- View的bounds和frame的区别
- frame,bounds的区别
- 台大机器学习笔记(12-16)——Nonlinear Transformation&Tips
- Java_Hql_Query_Basic
- 排列组合 用递归
- JavaScript生成不重复随机数
- Android开发颜色代码大全
- bounds和frame的区别
- 正则表达式(表达法)
- 【POJ 1151】 Atlantis(离散化+扫描线)
- [leetcode] 38. Count and Say
- 列表下拉刷新
- (OK) CentOS 7—adb—android-sdk_r24.3.3-linux.tgz
- Java高级部分之线程重点总结(上)
- 最近的javascrip学习心得及小心情
- 码农小汪-剑指Offer之25 -字符串的排列(全排列)