uiview frame,bounds,center 理解

基本概念:

frame: 该view在父view坐标系统中的位置和大小。(参照点是,父亲的坐标系统)

bounds:该view在本地坐标系统中的位置和大小。(参照点是,本地坐标系统)

center:该view的中心点在父view坐标系统中的位置和大小。(参照电是,父亲的坐标系统)

实际上只有bounds和center两个属性。frame是为了方便直观多加的属性。所以修改了一个可能会影响到其他属性。

文档中如下说:

Although you can set the values of these properties independently, setting the value for one changes the others in the following ways:        When you set the frame property, the size of the bounds property is set to match the size of the frameproperty. The center property is also adjusted to match the center point of the new frame. When you set the center property, the origin of the frame changes accordingly.        When you set the size of the bounds rectangle, 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属性影响到本地坐标系统的原点。需要注意。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值