<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIAttachmentBehavior/limitAttachment(with:offsetFromCenter:attachedTo:offsetFromCenter:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIAttachmentBehavior(cm)limitAttachmentWithItem:offsetFromCenter:attachedToItem:offsetFromCenter:"
  },
  "title" : "limitAttachment(with:offsetFromCenter:attachedTo:offsetFromCenter:)"
}
-->

# limitAttachment(with:offsetFromCenter:attachedTo:offsetFromCenter:)

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

```
class func limitAttachment(with item1: any UIDynamicItem, offsetFromCenter offset1: UIOffset, attachedTo item2: any 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`](/documentation/UIKit/UIOffset/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`](/documentation/UIKit/UIOffset/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`](/documentation/UIKit/UIAttachmentBehavior/length) property.

---

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)