搞iOS开发的童鞋基本都会用过UIView,那他的bounds和frame两个属性也不会陌生,那这两个有什么实质性的区别呢?

先看到下面的代码你肯定就明白了一些:

-(CGRect)frame{
    returnCGRectMake(self.frame.origin.x,self.frame.origin.y,self.frame.size.width,self.frame.size.height);
}
-(CGRect)bounds{
    returnCGRectMake(0,0,self.frame.size.width,self.frame.size.height);
}
很明显,bounds的原点是(0,0)点,而frame的原点却是任意的。

再来看张图,你就会更清楚了。

基本概念:

      frame:该view在父view坐标系统中的位置和大小。(参照点是,父亲的坐标系统)
      bounds:该view在本地坐标系统中的位置和大小。(参照点是,本地坐标系统)
      center:该view的中心点在父view坐标系统中的位置和大小。(参照电是,父亲的坐标系统)
实际上只有bounds和center两个属性。frame是为了方便直观多加的属性。所以修改了一个可能会影响到其他属性。文档中如下说:
      Although you can set the values of theseproperties independently, setting the value for one changes theothers in t
he following ways:
      When
you set the frame property, the sizeof the bounds property is set to
match the size of theframeproperty. The center property is also adjusted
to match thecenter point
of the new frame.
      When you set the center property, theorigin of the frame changes accordingly.
      When you set the size of the boundsrectangle, the size of the frame rectangle changes to match。
前两个很明显,最后一个bounds稍微有点费解。这里一定要顺便说下本地坐标系统:每个
view都有一个本地坐标系统。这个坐标系统作用比较重要,比如触摸的回调函数中的UITouch里面的>坐标值都是参照这个本地坐标系统的坐标。
当然bounds这个属性也是参照这个本地坐标系统来的。其实本地坐标系统的关键就是要知道的它的原点(0,0)在什么位置(这个位置又是相对于上层的
view的本地坐标系统而言的,当然最上面的一层view就是window它的本地坐标系统原点就是屏幕的左上角了)。通过修改view的bounds属
性可以修改本地坐标系统的原点位置。
修改bounds测试结果:
      bounds (0,0,100,100) -->(0,0,200,200) 本地坐标系统原点往左往上分别50。center不变,效果是按照中心放大view
      bounds(0,0,100,100) -->(100,100,100,100)本地坐标系统原点往左往上分别100。center不变,没有可视效果变化(但是本地坐标系统的原点已经改变)
      
结论:
     bounds属性影响到本地坐标系统的原点。需要注意

最新文章

  1. 我们为什么使用Node
  2. 在ubuntu上配置nginx+php+mysql+phpmyadmin
  3. C#调用SQL Server参数过程传参
  4. Eclipse连接到My sql数据库之前操作
  5. 当PullToRefreshScrollView里面嵌套ListView
  6. linux下自助获取帮助
  7. HDU 5281 Senior's Gun (贪心)
  8. Lua 数据类型和 Redis 数据类型之间转换
  9. snmp协议接口
  10. EFcore与动态模型(三)
  11. 201521123067 《Java程序设计》第5周学习总结
  12. PCI设备内存操作函数总结
  13. MFC中listbox控件中各种属性的详解
  14. 关于selenium的8种元素定位
  15. alias命令详解
  16. FJUT3703 这还是一道数论题(二分 + hash + manacher 或者 STL + hash 或者 后缀数组 + hash)题解
  17. linux c/c++ 获取文件大小
  18. Verilog中的有符号计算之认知补码
  19. Linux: grep多个关键字“与”和“或”
  20. 装载问题(load)

热门文章

  1. centos之jdk安装
  2. 什么是JSON对象
  3. fragment、ListFragment使用ListView及自定义Listview等初始化操作
  4. Unix/Linux环境C编程入门教程(5) Red Hat Enterprise Linux(RHEL)环境搭建
  5. ora-01031:insufficient privileges 解决方案
  6. poj1658
  7. 设置ToggleButton、Switch、CheckBox和RadioButton的显示效果
  8. Eclipse debug ‘Source not found’
  9. Cocos2d-x 3.1.1 学习日志6--30分钟了解C++11新特性
  10. 发现一个名为“Douyu”的国人项目