frame和bounds的区别
2019-07-03 本文已影响0人
我是小胡胡123
1,UIScrollView滚动显示原理
修改父视图的bounds的origin ,子视图的在父视图上位置改变,但是子视图的frame,bounds,center都没有改变。
这就是scrollview滑动的原理,实际上是在不断改变scrollview的bounds.origin,UIScrollView的实现就是通过bounds来实现的。contentOffset是bounds的origin。然后当bounds修改之后,会在layoutSubviews方法里面对子视图进行布局。

2,bounds不会影响自己本身的显示,但是它会影响子视图的显示偏移位置.
子视图的frame,bounds,center均不会改变,因为只是变了它的相对原点,任何视图的布局都是依赖于父视图所规定的原点做布局的
子视图的frame的origin 是相对于父视图的bounds的origin进行布局的
如果子视图frame的orgin是 30, 30, 父视图的bounds的origin是30,60, 那么子视图从视觉上就在父视图的frame的0,-30的位置显示
父 view 0,0的位置就已经是bounds.origin的位置了, 是从bounds.orign开始; 坐标原点正常是0,0,如果加上bounds.origin,此时原点对应的位置已经不是0,0,而是bounds.origin
