contentInset,contentOffset等概念的理解

frame, bounds, center

看一下源码就知道frame和bounds的区别了

1
2
3
4
5
6
-(CGRect)frame{
return CGRectMake(self.frame.origin.x,self.frame.origin.y,self.frame.size.width,self.frame.size.height);
}
-(CGRect)bounds{
return CGRectMake(0,0,self.frame.size.width,self.frame.size.height);
}

frame: 该view在父view坐标系统中的位置和大小。(参照点是:父亲的坐标系统
bounds:该view在本地坐标系统中的位置和大小。(参照点是:本地坐标系统,就相当于View自己的坐标系统,以0,0点为起点)
center:该view的中心点在父view坐标系统中的位置和大小。(参照点是:父亲的坐标系统

originframebounds的左上角坐标

contentInset和contentOffset

contentSize是contentView的大小

contentInset就相当于html中的padding,是view相对于子view的距离有四个属性
例如UIEdgeInsets(top: 10.0, left: 20.0, bottom: 30.0, right: 40.0)

contentOffset是scrollview当前显示区域顶点相对于frame顶点的偏移量

假如有一个ScrollView(scrollViewA),设置scrollViewA的contentInsetUIEdgeInsets(top: 10.0, left: 20.0, bottom: 30.0, right: 40.0)
那么
scrollViewAbounds(-20,-10)
scrollViewAcontentOffset(-20,-10)
scrollViewA的内容滚动时contentSize是不变的
contentInset也是不变的
变得只是contentOffsetbounds
并且contentOffsetbounds的值是一样的
上拉y变大,下拉y变小
左拉x变大,右拉x变小

可以这样想以scrollViewA左上角为坐标系原点y轴向上为正x轴向左为正,那么contentOffsetbounds就是contentView左上角在该坐标系的坐标