Contents

targetContentOffset(forProposedContentOffset:withScrollingVelocity:)

Retrieves the point at which to stop scrolling.

Declaration

func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint

Parameters

  • proposedContentOffset:

    The proposed point (in the collection view’s content view) at which to stop scrolling. This is the value at which scrolling would naturally stop if no adjustments were made. The point reflects the upper-left corner of the visible content.

  • velocity:

    The current scrolling velocity along both the horizontal and vertical axes. This value is measured in points per second.

Return Value

The content offset that you want to use instead. This value reflects the adjusted upper-left corner of the visible area. The default implementation of this method returns the value in the proposedContentOffset parameter.

Discussion

If you want the scrolling behavior to snap to specific boundaries, you can override this method and use it to change the point at which to stop. For example, you might use this method to always stop scrolling on a boundary between items, as opposed to stopping in the middle of an item.

See Also

Providing layout attributes