iOS Developer Library

Developer

UIKit Framework Reference UICollisionBehaviorDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

UICollisionBehaviorDelegate

Inheritance


Not Applicable

Conforms To


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 7.0 and later.

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

The delegate is notified of collisions that occur between the behavior’s dynamic items, or between a dynamic item and a boundary, depending on the behavior’s mode (as set with its collisionMode property). In the case of a collision between an item and the boundary defined by a reference view, the identifier passed to the delegate method is nil. (For more on the reference view and the different ways to initialize a dynamic animator, read the Overview in UIDynamicAnimator Class Reference.)

  • Called when a collision, between a dynamic item and a collision boundary, has begun.

    Declaration

    Swift

    optional func collisionBehavior(_ behavior: UICollisionBehavior, beganContactForItem item: UIDynamicItem, withBoundaryIdentifier identifier: NSCopying, atPoint p: CGPoint)

    Objective-C

    - (void)collisionBehavior:(UICollisionBehavior *)behavior beganContactForItem:(id<UIDynamicItem>)item withBoundaryIdentifier:(id<NSCopying>)identifier atPoint:(CGPoint)p

    Parameters

    behavior

    The collision behavior that owns the dynamic item that has started contact with a boundary.

    item

    The dynamic item that has started contact with a boundary.

    identifier

    The identifier of the boundary that the dynamic item has started contact with.

    p

    The collision point on the boundary.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Called when a collision between two dynamic items has begun.

    Declaration

    Swift

    optional func collisionBehavior(_ behavior: UICollisionBehavior, beganContactForItem item1: UIDynamicItem, withItem item2: UIDynamicItem, atPoint p: CGPoint)

    Objective-C

    - (void)collisionBehavior:(UICollisionBehavior *)behavior beganContactForItem:(id<UIDynamicItem>)item1 withItem:(id<UIDynamicItem>)item2 atPoint:(CGPoint)p

    Parameters

    behavior

    The collision behavior that owns the dynamic items that have started to contact each other.

    item1

    The first of the two dynamic items participating in the collision.

    item2

    The second of the two dynamic items participating in the collision.

    p

    The contact point for the collision. The coordinate system that pertains to a collision depends on how you initialized the associated animator. For details, read the Overview of UIDynamicAnimator Class Reference.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Called when a collision between a dynamic item and a boundary has ended.

    Declaration

    Swift

    optional func collisionBehavior(_ behavior: UICollisionBehavior, endedContactForItem item: UIDynamicItem, withBoundaryIdentifier identifier: NSCopying)

    Objective-C

    - (void)collisionBehavior:(UICollisionBehavior *)behavior endedContactForItem:(id<UIDynamicItem>)item withBoundaryIdentifier:(id<NSCopying>)identifier

    Parameters

    behavior

    The collision behavior that owns the dynamic item that has ended contact.

    item

    The dynamic item that collided.

    identifier

    The identifier of the boundary that the dynamic item collided with.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Called when a collision between two dynamic items has ended.

    Declaration

    Swift

    optional func collisionBehavior(_ behavior: UICollisionBehavior, endedContactForItem item1: UIDynamicItem, withItem item2: UIDynamicItem)

    Objective-C

    - (void)collisionBehavior:(UICollisionBehavior *)behavior endedContactForItem:(id<UIDynamicItem>)item1 withItem:(id<UIDynamicItem>)item2

    Parameters

    behavior

    The collision behavior that owns the dynamic items that collided.

    item1

    The first of the two dynamic items participating in the collision.

    item2

    The second of the two dynamic items participating in the collision.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.