slidingAttachment(with:attachedTo:attachmentAnchor:axisOfTranslation:)
Creates and returns an attachment behavior where two items are fixed to points that slide along the specified axis.
Declaration
class func slidingAttachment(with item1: any UIDynamicItem, attachedTo item2: any UIDynamicItem, attachmentAnchor point: CGPoint, axisOfTranslation axis: CGVector) -> SelfParameters
- item1:
The first of two dynamic items connected by the attachment behavior.
- item2:
The second of two dynamic items connected by the attachment behavior.
- point:
The initial anchor point for both items. Specify this point in the coordinate system of the dynamic animator’s reference view. For more information about coordinate systems, see Uidynamicanimator.
- axis:
The axis of translation, along which the anchor points of the items slide.
Return Value
A new attachment object or nil if the object could not be created.
Discussion
For this behavior, each item acts like it is at the end of a solid rod attached to its anchor point. Both items start with the same anchor point, but as animations progress, each item’s anchor point is allowed to slide along the specified axis of translation independently. So if one item moves, it pushes the translation axis and the other item with it. The items do not rotate relative to the axis of translation or to each other, but the proximity of the items to one another varies depending on the movement of each item’s anchor point along the translation axis.
The axis of translation is infinitely long initially, but you can change the length by assigning a new value to the attachmentRange property. When specifying a new attachment range, remember that the value in point represents the value 0 on the axis. Any new range you specify must include 0.
See Also
Creating and initializing attachment behavior objects
slidingAttachment(with:attachmentAnchor:axisOfTranslation:)fixedAttachment(with:attachedTo:attachmentAnchor:)limitAttachment(with:offsetFromCenter:attachedTo:offsetFromCenter:)pinAttachment(with:attachedTo:attachmentAnchor:)init(item:attachedToAnchor:)init(item:attachedTo:)init(item:offsetFromCenter:attachedToAnchor:)init(item:offsetFromCenter:attachedTo:offsetFromCenter:)