contentSize、contentInset和contentOffset区别

 

contentSize表示的是整个Scrollview的内容大小,contentOffset表示的是当前显示区域顶点相对于frame顶点的偏移量。

contentSize 是scrollview中的一个属性,它代表scrollview中的可显示区域,假如有一个scrollview,它的frame为(0,0,320,480),而它的contentSize为(320,960).

也就是说,这个scrollview整个内容的大小为(320,960),要通过上下滑动scrollview来查看(320,480)后的内容。

contentOffset 是scrollview当前显示区域顶点相对于frame顶点的偏移量,比如上个例子你拉到最下面,contentoffset就是(0 ,480),也就是y偏移了480

contentInset 是scrollview中contentView.frame.origin与scrollview.frame.origin的关系,比如contentView的frame为(0,30,320,480),那么contentInset则为(0, 30),

scrollView.contentInset = UIEdgeInsetsMake(30, 0, 0, 0);

这样定义后,内容视图开始显示的坐标为(0,31)。

原文地址:https://www.cnblogs.com/wuxiufang/p/3597193.html