Contents

UIAttachmentBehavior

A relationship between two dynamic items, or between a dynamic item and an anchor point.

Declaration

@MainActor class UIAttachmentBehavior

Overview

When two items are attached to each other, forces imparted on one item affect the movement of the other in a prescribed way. When an item is attached to an anchor point, the movement of that item is affected by its attachment to the specified anchor point. Some attachment behaviors support both two items and an anchor point.

You specify type of attachment behavior you want at creation time. This class offers many creation and initialization methods, each of which creates a different type of attachment behavior, which cannot be changed later. However, you may change specific attributes of the attachment behavior using the properties of this class. For example, you can change the distance between two attached items or change the damping forces applied to the items.

Applying an Attachment Behavior to Dynamic Items

To apply an attachment behavior to your dynamic items, do the following:

  1. Create the attachment behavior using one of the creation or initialization methods. The method you choose defines the relationship between the items and the anchor point (if any).

  2. Enable the attachment behavior by adding it to your UIDynamicAnimator object using the addBehavior(_:) method. Do not add the same attachment behavior to multiple animator objects.

The attachment behavior derives its coordinate system from the reference view of its associated dynamic animator object. For more information about the dynamic animator and the reference coordinate system, see UIDynamicAnimator.

Topics

Creating and initializing attachment behavior objects

Getting the attached items

Configuring an attachment behavior

Constants

Initializers

See Also

Behaviors