Type Method

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: UIDynamicItem, offsetFromCenter offset1: UIOffset, attachedTo item2: 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

class func slidingAttachment(with: UIDynamicItem, attachmentAnchor: CGPoint, axisOfTranslation: CGVector) -> Self

Creates and returns an attachment behavior where one item slides along the specified axis.

class func slidingAttachment(with: UIDynamicItem, attachedTo: UIDynamicItem, attachmentAnchor: CGPoint, axisOfTranslation: CGVector) -> Self

Creates and returns an attachment behavior where two items are fixed to points that slide along the specified axis.

class func fixedAttachment(with: UIDynamicItem, attachedTo: UIDynamicItem, attachmentAnchor: CGPoint) -> Self

Creates and returns an attachment behavior where the two items are fixed together through the specified anchor point.

class func pinAttachment(with: UIDynamicItem, attachedTo: UIDynamicItem, attachmentAnchor: CGPoint) -> Self

Creates and returns an attachment behavior where the two items are pinned to, and move around, an anchor point

init(item: UIDynamicItem, attachedToAnchor: CGPoint)

Initializes a behavior where the center of a dynamic item is attached to the specified anchor point.

init(item: UIDynamicItem, attachedTo: UIDynamicItem)

Initializes a behavior where the centers of two dynamic items are attached to each other.

init(item: UIDynamicItem, offsetFromCenter: UIOffset, attachedToAnchor: CGPoint)

Initializes a behavior where the specified point in a dynamic item is attached to an anchor point.

init(item: UIDynamicItem, offsetFromCenter: UIOffset, attachedTo: UIDynamicItem, offsetFromCenter: UIOffset)

Initializes an attachment behavior that connects a specified point in one dynamic item to a specified point in another dynamic item.