<!--
{
  "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/UICollisionBehavior",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UICollisionBehavior"
  },
  "title" : "UICollisionBehavior"
}
-->

# UICollisionBehavior

An object that confers to a specified array of dynamic items the ability to engage in collisions with each other and with the behavior’s specified boundaries.

```
@MainActor class UICollisionBehavior
```

## Overview

A collision behavior also specifies some characteristics of its items’ collisions, with other characteristics optionally specified by a [`UIDynamicItemBehavior`](/documentation/UIKit/UIDynamicItemBehavior) object. A *dynamic item* is any iOS or custom object that conforms to the [`UIDynamicItem`](/documentation/UIKit/UIDynamicItem) protocol. The [`UIView`](/documentation/UIKit/UIView) and [`UICollectionViewLayoutAttributes`](/documentation/UIKit/UICollectionViewLayoutAttributes) classes implement this protocol starting in iOS 7.0. You can use a custom object as a dynamic item for such purposes as reacting to rotation or position changes computed by a dynamic animator—an instance of the [`UIDynamicAnimator`](/documentation/UIKit/UIDynamicAnimator) class.

To use a collision behavior with a dynamic item, perform these two steps:

1. Associate the item with the behavior using the [`addItem(_:)`](/documentation/UIKit/UICollisionBehavior/addItem(_:)) method, or initialize a new collision behavior with an array of items using the [`init(items:)`](/documentation/UIKit/UICollisionBehavior/init(items:)) method.
2. Enable the behavior by adding it to an animator using the [`addBehavior(_:)`](/documentation/UIKit/UIDynamicAnimator/addBehavior(_:)) method

The coordinate system that pertains to a collision behavior, and the types of dynamic items you can use with the behavior, depend on how you initialized the associated animator. For details, read the Overview of [`UIDynamicAnimator`](/documentation/UIKit/UIDynamicAnimator).

You can add multiple collision behaviors to a dynamic animator. A dynamic item can be part of any number of collision behaviors, provided those behaviors belong to the same animator. For example, you can specify a collision behavior for a set of say, blue, items and another for, say, pink items. When you add both behaviors to a dynamic animator, blue items can collide with each other and pink items can collide with each other, but a blue item and a pink item would not collide—they would ignore each other.

By default, a collision behavior’s items can collide with each other *and* with any boundaries you’ve specified for the behavior. If you want to specify that a behavior’s items collide only with each other, or only with boundaries, explicitly set the [`collisionMode`](/documentation/UIKit/UICollisionBehavior/collisionMode) property.

You can define a collision boundary with a bezier path (see the [`addBoundary(withIdentifier:for:)`](/documentation/UIKit/UICollisionBehavior/addBoundary(withIdentifier:for:)) method) or with a line segment (see the [`addBoundary(withIdentifier:from:to:)`](/documentation/UIKit/UICollisionBehavior/addBoundary(withIdentifier:from:to:)) method). When you use a collision behavior with a dynamic animator you’ve initialized with a reference view or a collection view layout, you can also specify a collision boundary according to the bounds of the dynamic animator’s coordinate system (see the [`setTranslatesReferenceBoundsIntoBoundary(with:)`](/documentation/UIKit/UICollisionBehavior/setTranslatesReferenceBoundsIntoBoundary(with:)) method).

> Important:
> When setting the initial position for a dynamic item, you must ensure that its bounds do not intersect any collision boundaries. The animation behavior for such a misplaced item is undefined.

To respond to collisions, implement a delegate object that adopts the [`UICollisionBehaviorDelegate`](/documentation/UIKit/UICollisionBehaviorDelegate) protocol. Add the delegate to the behavior using the [`collisionDelegate`](/documentation/UIKit/UICollisionBehavior/collisionDelegate) property.

You can include a collision behavior in a custom, composite behavior by starting with a [`UIDynamicBehavior`](/documentation/UIKit/UIDynamicBehavior) object and adding a collision behavior with the [`addChildBehavior(_:)`](/documentation/UIKit/UIDynamicBehavior/addChildBehavior(_:)) method.  If you want to influence a collision behavior at each step of a dynamic animation, implement the inherited [`action`](/documentation/UIKit/UIDynamicBehavior/action) method.

## Topics

### Initializing and managing a collision behavior

[`-  addItem:`](/documentation/UIKit/UICollisionBehavior/addItem(_:))

Adds a dynamic item to the collision behavior’s item array.

[`-  initWithItems:`](/documentation/UIKit/UICollisionBehavior/init(items:))

Initializes a collision behavior with an array of dynamic items.

[`-  removeItem:`](/documentation/UIKit/UICollisionBehavior/removeItem(_:))

Removes a specific dynamic item from the collision behavior.

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

Returns the set of dynamic items you’ve added to the collision behavior.

### Customizing the collision behavior

[`collisionDelegate`](/documentation/UIKit/UICollisionBehavior/collisionDelegate)

The delegate object that you want to respond to collisions for the collision behavior.

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

To respond to UIKit dynamic item collisions, configure a custom class to adopt the [`UICollisionBehaviorDelegate`](/documentation/UIKit/UICollisionBehaviorDelegate) protocol. Then, in a collision behavior (an instance of the [`UICollisionBehavior`](/documentation/UIKit/UICollisionBehavior) class), set the delegate to be an instance of your custom class.

### Configuring a collision behavior

[`-  addBoundaryWithIdentifier:forPath:`](/documentation/UIKit/UICollisionBehavior/addBoundary(withIdentifier:for:))

Adds a collision boundary, specified as a Bezier path, to the collision behavior.

[`-  addBoundaryWithIdentifier:fromPoint:toPoint:`](/documentation/UIKit/UICollisionBehavior/addBoundary(withIdentifier:from:to:))

Adds a collision boundary, specified as a line segment, to the collision behavior.

[`boundaryIdentifiers`](/documentation/UIKit/UICollisionBehavior/boundaryIdentifiers)

The set of boundary identifiers that you’ve added to the collision behavior.

[`-  boundaryWithIdentifier:`](/documentation/UIKit/UICollisionBehavior/boundary(withIdentifier:))

Returns a specified Bezier-path boundary.

[`collisionMode`](/documentation/UIKit/UICollisionBehavior/collisionMode)

The type of edges that participate in collisions for the collision behavior.

[`-  removeAllBoundaries`](/documentation/UIKit/UICollisionBehavior/removeAllBoundaries())

Removes all previously-specified collision boundaries from the collision behavior.

[`-  removeBoundaryWithIdentifier:`](/documentation/UIKit/UICollisionBehavior/removeBoundary(withIdentifier:))

Removes a specific collision boundary from the collision behavior.

[`-  setTranslatesReferenceBoundsIntoBoundaryWithInsets:`](/documentation/UIKit/UICollisionBehavior/setTranslatesReferenceBoundsIntoBoundary(with:))

Specifies a collision boundary based on the bounds of the animation reference system, with optional insets.

[`translatesReferenceBoundsIntoBoundary`](/documentation/UIKit/UICollisionBehavior/translatesReferenceBoundsIntoBoundary)

Specifies whether a boundary based on the reference system is active.

### Constants

[`Mode`](/documentation/UIKit/UICollisionBehavior/Mode)

The types of edges that participate in collisions for a collision behavior.

## Relationships

### Conforms To

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

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

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

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

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

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

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

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

### 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)