Instance Method

targetContentOffset(forProposedContentOffset:withScrollingVelocity:)

Returns 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

class var layoutAttributesClass: AnyClass

Returns the class to use when creating layout attributes objects.

func prepare()

Tells the layout object to update the current layout.

func layoutAttributesForElements(in: CGRect) -> [UICollectionViewLayoutAttributes]?

Returns the layout attributes for all of the cells and views in the specified rectangle.

func layoutAttributesForItem(at: IndexPath) -> UICollectionViewLayoutAttributes?

Returns the layout attributes for the item at the specified index path.

func layoutAttributesForInteractivelyMovingItem(at: IndexPath, withTargetPosition: CGPoint) -> UICollectionViewLayoutAttributes

Returns the layout attributes of an item when it is being moved interactively by the user.

func targetContentOffset(forProposedContentOffset: CGPoint) -> CGPoint

Returns the content offset to use after an animated layout update or change.