问题描述
UIScrollView中的contentOffset属性有什么用?
推荐答案
根据文档,contentOffset属性代表:
原点内容视图从原点偏移滚动视图.
The point at which the origin of the content view is offset from the origin of the scroll view.
简单来说,就是视图在每个方向(垂直和水平)上移动了多远.您可以通过访问 CGPoint 的 x 和 y 属性来解包垂直和水平距离:
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;