fram和bounds的区别和用途 - iOS - UI基础知识总结2
来源:互联网 发布:c语言的指针编程例题 编辑:程序博客网 时间:2024/05/20 20:57
// fram__________________________________
// 子视图的fram是相对于父视图的,改变fram的内容会改变子视图自己在父视图中的位置和大小,但是对父视图没有影响
// 设置fram时可以超出父视图边界范围(超出部分不会在父视图上展现)(比如:设置成(-10,-10,100,100))
UIView *redView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
redView.backgroundColor = [UIColor redColor];
[containerView addSubview:redView];
[redView release];
// 子视图的fram的起始位置(原点坐标)是针对父视图的 起始位置
// 父视图的fram的改变不会影响它的子视图在它上面的 相对位置
UIView *blueView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];// fram里面的原点(0,0)是相对于父视图的
blueView.backgroundColor = [UIColor blueColor];
[redView addSubview:blueView];
[blueView release];
// 当本身的fram和center发生冲突时,fram要遵从center的改变(改变center会引起fram跟着做出相应改变)
blueView.center = CGPointMake(50, 50);
NSLog(@"%f , %f",blueView.center.x , blueView.center.y);
NSLog(@"%@",blueView);
// bounds__________________________________
// bounds的改变对本身没有影响(自己相对于自己的父视图不会有偏移),但是会影响它上面的子视图的位置(它的子视图相对于它会有所偏移)
NSLog(@"bounds.x = %.2f , bounds.y = %.2f , bounds.width = %.2f , bounds.height = %.2f",redView.bounds.origin.x , redView.bounds.origin.y , redView.bounds.size.width , redView.bounds.size.height);
// 子视图的fram是相对于父视图的,改变fram的内容会改变子视图自己在父视图中的位置和大小,但是对父视图没有影响
// 设置fram时可以超出父视图边界范围(超出部分不会在父视图上展现)(比如:设置成(-10,-10,100,100))
UIView *redView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
redView.backgroundColor = [UIColor redColor];
[containerView addSubview:redView];
[redView release];
// 子视图的fram的起始位置(原点坐标)是针对父视图的 起始位置
// 父视图的fram的改变不会影响它的子视图在它上面的 相对位置
UIView *blueView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];// fram里面的原点(0,0)是相对于父视图的
blueView.backgroundColor = [UIColor blueColor];
[redView addSubview:blueView];
[blueView release];
// 当本身的fram和center发生冲突时,fram要遵从center的改变(改变center会引起fram跟着做出相应改变)
blueView.center = CGPointMake(50, 50);
NSLog(@"%f , %f",blueView.center.x , blueView.center.y);
NSLog(@"%@",blueView);
// bounds__________________________________
// bounds的改变对本身没有影响(自己相对于自己的父视图不会有偏移),但是会影响它上面的子视图的位置(它的子视图相对于它会有所偏移)
NSLog(@"bounds.x = %.2f , bounds.y = %.2f , bounds.width = %.2f , bounds.height = %.2f",redView.bounds.origin.x , redView.bounds.origin.y , redView.bounds.size.width , redView.bounds.size.height);
redView.bounds = CGRectMake(10, 10, 100, 100);
// 系统内部存放的是视图的中心点位置和大小信息,Frame方式的信息是按照中心点位置计算出来的。当我们创建一个视图的时,一般采用Frame方式。当我们旋转一个视图或者处理视图事件时,大多采用bounds方式(让其父视图的bounds改变,从而引起该视图在其父视图上的位置的改变)。
0 0
- fram和bounds的区别和用途 - iOS - UI基础知识总结2
- iOS之UI基础---frame和bounds的区别
- iOS 中frame 和 bounds 的区别
- iOS中frame和bounds的区别
- iOS Frame和bounds的区别
- iOS View frame和bounds的区别
- iOS---frame和bounds的区别
- iOS,frame和bounds的区别
- iOS中frame和bounds的区别
- iOS中frame和bounds的区别
- iOS开发总结之 view的frame、center和和view的bounds之间的区别
- 对于iOS的fram,bounds,center的理解
- [ios ui][[UIScreen mainScreen] bounds]和 applicationFrame
- iOS界面篇 - bounds和frame的相同和区别
- iOS frame和Bounds 以及frame和bounds区别
- iOS 一一 frame和Bounds 以及frame和bounds区别
- iOS view的frame和bounds的区别
- frame 和bounds 的区别
- Oracle学习(二)之控制文件多工
- C#几种截取字符串的方法小结
- javascript对象的使用
- One Importance Difference between Stored Procedure and Stored Function
- 业界良心机构解密:90后更适合学网络营销的六大理由!
- fram和bounds的区别和用途 - iOS - UI基础知识总结2
- shader基础知识
- 五大常用算法之二:动态规划算法
- hsacm-1443
- 【Android】No resource found that matches the given name “xxx” 的解决方法
- 水题
- iOS8 模糊视图(毛玻璃效果) UIVisualEffectView
- 原生态JS取checkbox选中状态
- Mysql基础入门