<!--
{
  "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/slidingAttachment(with:attachmentAnchor:axisOfTranslation:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIAttachmentBehavior(cm)slidingAttachmentWithItem:attachmentAnchor:axisOfTranslation:"
  },
  "title" : "slidingAttachment(with:attachmentAnchor:axisOfTranslation:)"
}
-->

# slidingAttachment(with:attachmentAnchor:axisOfTranslation:)

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

```
class func slidingAttachment(with item: any UIDynamicItem, attachmentAnchor point: CGPoint, axisOfTranslation axis: CGVector) -> Self
```

## Parameters

`item`

The dynamic item connected by the attachment behavior.

`point`

The initial anchor point for the item. Specify this point in the coordinate system of the dynamic animator’s reference view. For more information about coordinate systems, see [`UIDynamicAnimator`](/documentation/UIKit/UIDynamicAnimator).

`axis`

The axis of translation, along which the item’s anchor point slides. The magnitude of the vector is ignored. Use the [`attachmentRange`](/documentation/UIKit/UIAttachmentBehavior/attachmentRange) property to define the distance that the anchor point can travel along the vector.

## Return Value

A new attachment object or `nil` if the object could not be created.

## Discussion

The behavior created by this method acts like a solid rod between `item` and the anchor point whose initial position you specify using the `point` parameter. As forces are applied to the item, the item’s anchor point slides along the specified `axis`, causing the item to move with it. The item does not rotate relative to the axis of translation or anchor point.

The axis of translation is infinitely long initially, but you can change the length by assigning a new value to the [`attachmentRange`](/documentation/UIKit/UIAttachmentBehavior/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`.

You can use this behavior to create an effect of an item sliding in a specific direction in response to other forces. For example, using the vector (0.0, 1.0) would cause the item to slide only vertically.

---

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)