Contents

limitAttachment(with:offsetFromCenter:attachedTo:offsetFromCenter:)

Creates and returns an attachment behavior object where two items are constrained by a maximum distance from one another.

Declaration

class func limitAttachment(with item1: any UIDynamicItem, offsetFromCenter offset1: UIOffset, attachedTo item2: any UIDynamicItem, offsetFromCenter offset2: UIOffset) -> Self

Parameters

  • item1:

    The first of two dynamic items connected by the attachment behavior.

  • offset1:

    The offset from the center of item1 that corresponds to the attachment point. Use an offset value to create rotational torque on the item. To pull the item from its center, specify Zero.

  • item2:

    The second of two dynamic items connected by the attachment behavior.

  • offset2:

    The offset from the center of item2 that corresponds to the attachment point. Use an offset value to create rotational torque on the item. To pull the item from its center, specify Zero.

Return Value

A new attachment object or nil if the object could not be created.

Discussion

The behavior created by this method is like connecting two items with a rope. The only constraint between the items is the maximum distance between them, which corresponds to the moment when the rope is taut. At other times, the objects move freely relative to one another.

The initial maximum distance between the items is set using the current position of the items. You can change the maximum distance by modifying the length property.

See Also

Creating and initializing attachment behavior objects