What does contentOffset do in a UIScrollView?

2019-01-16 12:37发布

What is the use of the contentOffset property in UIScrollView?

2条回答
爷、活的狠高调
2楼-- · 2019-01-16 12:42

According to the documentation, the contentOffset property represents:

The point at which the origin of the content view is offset from the origin of the scroll view.

In plain speak, it's how far the view has moved in each direction (vertical and horizontal). You can unpack vertical and horizontal distance by accessing the x and y properties of the CGPoint:

CGFloat xOffset = _myScrollView.contentOffset.x;
CGFloat yOffset = _myScrollView.contentOffset.y;
查看更多
萌系小妹纸
3楼-- · 2019-01-16 12:45

It could be considered as the coordinate of the origin of scrollView's frame relative to the origin of its contentView's frame. See the picture below:

enter image description here

查看更多
登录 后发表回答