iOS开发 --frame和bounds区别详解
来源:互联网 发布:bp神经网络算法 matlab 编辑:程序博客网 时间:2024/06/13 23:31
frame和bounds
首先来说一下frame和bounds的个人理解:
frame:view.frame的意思是这个view在父视图本地参考坐标系(bounds)上的位置与大小
bounds:view.bounds是这个view自身的本地参考坐标系(位置与大小)供其子视图使用
这么说你肯定不太懂,但是看我带图洗脑
// 创建view1 let view1 = UIView() view1.backgroundColor = UIColor.yellow view1.frame = CGRect(x: 50, y: 50, width: 100, height: 100) self.view.addSubview(view1)
请记住这个黄色视图的center(中点),当你去修改bounds会跟它相关
1.bounds的size属性
// 设置boundsview1.bounds = CGRect(x: 0, y: 0, width: 50, height: 50)
只改变view1.bounds.size,这个时候view1的center不变,view1的大小随center缩放,修改后view1.frame也随之发生变化view1.frame = (75.0, 75.0, 50.0, 50.0)
2.bounds的origin属性
// 设置bounds let view1 = UIView() view1.backgroundColor = UIColor.yellow view1.frame = CGRect(x: 50, y: 50, width: 100, height: 100) view1.bounds = CGRect(x: -20, y: -20, width: 100, height: 100) self.view.addSubview(view1) // view1上添加子视图 let view2 = UIView() view2.backgroundColor = UIColor.red.withAlphaComponent(0.5) view2.frame = CGRect(x: 0, y: 0, width: 50, height: 50) view1.addSubview(view2)
> 由此可见:1.因为view1.bounds.size没变所以view1.frame没有改变, 2.view1.bounds.origin改变影响了view1子视图的位置,所以view1.bounds.origin是view2.frame.origin的参考 3.view1.bounds.origin的修改是根据view1左上角为原点参考
3.bounds的x,y,width和height四个属性同时修改
// 设置bounds let view1 = UIView() view1.backgroundColor = UIColor.yellow view1.frame = CGRect(x: 50, y: 50, width: 100, height: 100) view1.bounds = CGRect(x: -20, y: -20, width: 70, height: 70) self.view.addSubview(view1) // 子视图frame不变 let view2 = UIView() view2.backgroundColor = UIColor.red.withAlphaComponent(0.5) view2.frame = CGRect(x: 0, y: 0, width: 50, height: 50) view1.addSubview(view2)
由此可见,同时修改bounds的4个属性,
1.先修改bounds.size属性,将view1的位置和大小设置好得出修改后的frame
2.然后根据修改后view1左上角原点来修改view1.bounds.origin,从而改变view1的子视图的位置
阅读全文
0 0
- iOS开发 --frame和bounds区别详解
- iOS frame和Bounds 以及frame和bounds区别
- iOS 一一 frame和Bounds 以及frame和bounds区别
- iOS开发——frame和bounds详解
- iOS开发——frame和bounds详解
- iOS开发——frame和bounds详解
- iOS frame与bounds区别详解
- IOS开发之UIView(bounds,frame)区别
- 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开发中的frame和bounds
- ios bounds 和 frame
- 深度优先搜索(DFS)
- PHP 5 Date/Time 函数
- dp入门级--递推数塔
- QT+Gsoap访问cxf WebService
- PHP 5 Directory 函数
- iOS开发 --frame和bounds区别详解
- linux服务器上配置多个svn仓库
- 352A
- bzoj 1257: [CQOI2007]余数之和sum
- order by语句使用
- Linux命令-cut
- 基于IntelliJ IDEA15 搭建最简单的maven项目
- 学习笔记 STL Map
- POJ 2104 分桶