<!--
{
  "availability" : [
    "iOS: 7.0.0 -",
    "iPadOS: 7.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIAttachmentBehavior",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIAttachmentBehavior"
  },
  "title" : "UIAttachmentBehavior"
}
-->

# UIAttachmentBehavior

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

```
@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`](/documentation/UIKit/UIDynamicAnimator) object using the [`addBehavior(_:)`](/documentation/UIKit/UIDynamicAnimator/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`](/documentation/UIKit/UIDynamicAnimator).

## Topics

### Creating and initializing attachment behavior objects

[`+  slidingAttachmentWithItem:attachmentAnchor:axisOfTranslation:`](/documentation/UIKit/UIAttachmentBehavior/slidingAttachment(with:attachmentAnchor:axisOfTranslation:))

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

[`+  slidingAttachmentWithItem:attachedToItem:attachmentAnchor:axisOfTranslation:`](/documentation/UIKit/UIAttachmentBehavior/slidingAttachment(with:attachedTo:attachmentAnchor:axisOfTranslation:))

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

[`+  fixedAttachmentWithItem:attachedToItem:attachmentAnchor:`](/documentation/UIKit/UIAttachmentBehavior/fixedAttachment(with:attachedTo:attachmentAnchor:))

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

[`+  limitAttachmentWithItem:offsetFromCenter:attachedToItem:offsetFromCenter:`](/documentation/UIKit/UIAttachmentBehavior/limitAttachment(with:offsetFromCenter:attachedTo:offsetFromCenter:))

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

[`+  pinAttachmentWithItem:attachedToItem:attachmentAnchor:`](/documentation/UIKit/UIAttachmentBehavior/pinAttachment(with:attachedTo:attachmentAnchor:))

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

[`-  initWithItem:attachedToAnchor:`](/documentation/UIKit/UIAttachmentBehavior/init(item:attachedToAnchor:))

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

[`-  initWithItem:attachedToItem:`](/documentation/UIKit/UIAttachmentBehavior/init(item:attachedTo:))

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

[`-  initWithItem:offsetFromCenter:attachedToAnchor:`](/documentation/UIKit/UIAttachmentBehavior/init(item:offsetFromCenter:attachedToAnchor:))

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

[`-  initWithItem:offsetFromCenter:attachedToItem:offsetFromCenter:`](/documentation/UIKit/UIAttachmentBehavior/init(item:offsetFromCenter:attachedTo:offsetFromCenter:))

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

[`items`](/documentation/UIKit/UIAttachmentBehavior/items)

The dynamic items connected by the attachment behavior.

### Configuring an attachment behavior

[`anchorPoint`](/documentation/UIKit/UIAttachmentBehavior/anchorPoint)

The anchor point for the attachment behavior, if any.

[`attachedBehaviorType`](/documentation/UIKit/UIAttachmentBehavior/attachedBehaviorType)

The type of the attachment behavior.

[`damping`](/documentation/UIKit/UIAttachmentBehavior/damping)

The amount of damping to apply to the attachment behavior.

[`frequency`](/documentation/UIKit/UIAttachmentBehavior/frequency)

The frequency of oscillation for the attachment behavior.

[`length`](/documentation/UIKit/UIAttachmentBehavior/length)

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

[`frictionTorque`](/documentation/UIKit/UIAttachmentBehavior/frictionTorque)

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

[`attachmentRange`](/documentation/UIKit/UIAttachmentBehavior/attachmentRange)

The range of motion for the attachment behavior.

### Constants

[`AttachmentType`](/documentation/UIKit/UIAttachmentBehavior/AttachmentType)

Constants indicating the type of the attachment behavior object.

[`UIFloatRange`](/documentation/UIKit/UIFloatRange)

The range of motion for attached objects.

[Float range constants](/documentation/UIKit/float-range-constants)

Constants for specifying standard ranges.

[`UIOffset`](/documentation/UIKit/UIOffset)

A structure that specifies an amount to offset a position.

## Relationships

### Conforms To

[`Sendable`](/documentation/Swift/Sendable)

[`Equatable`](/documentation/Swift/Equatable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Hashable`](/documentation/Swift/Hashable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

### Inherits From

[`UIDynamicBehavior`](/documentation/UIKit/UIDynamicBehavior)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)