Class

UIAttachmentBehavior

A UIAttachmentBehavior object creates a relationship between two dynamic items, or between a dynamic item and an anchor point. 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.

Overview

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.

Symbols

Creating and Initializing Attachment Behavior Objects

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

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)

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)

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

class func limitAttachment(with: UIDynamicItem, offsetFromCenter: UIOffset, attachedTo: UIDynamicItem, offsetFromCenter: UIOffset)

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

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

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.

Getting the Attached Items

var items: [UIDynamicItem]

The dynamic items connected by the attachment behavior.

Configuring an Attachment Behavior

var anchorPoint: CGPoint

The anchor point for the attachment behavior, if any.

var attachedBehaviorType: UIAttachmentBehaviorType

The type of the attachment behavior.

var damping: CGFloat

The amount of damping to apply to the attachment behavior.

var frequency: CGFloat

The frequency of oscillation for the attachment behavior.

var length: CGFloat

The distance, in points, between the two attachment points of the attachment behavior.

var frictionTorque: CGFloat

The amount of force needed to overcome rotational forces around an anchor point.

var attachmentRange: UIFloatRange

The range of motion for the attachment behavior.

Constants

UIAttachmentBehaviorType

Constants indicating the type of the attachment behavior object.

UIFloatRange

The range of motion for attached objects.

Float Range Constants

Constants for specifying standard ranges.

Relationships

Inherits From