Search code examples
iphoneuiscrollview

What does contentOffset do in a UIScrollView?


What is the use of the contentOffset property in UIScrollView?


Solution

  • 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;