iOS Developer Library

Developer

UIKit Framework Reference UICollisionBehavior Class Reference

Options
Deployment Target:

On This Page
Language:

UICollisionBehavior

A collision behavior confers, to a specified array of dynamic items, the ability of those items to engage in collisions with each other and with the behavior’s specified boundaries. A collision behavior also specifies some characteristics of its items’ collisions, with other characteristics optionally specified by a UIDynamicItemBehavior object. More...

Inheritance


Conforms To


Import Statement


import UIKit @import UIKit;

Availability


Available in iOS 7.0 and later.
  • Adds a dynamic item to the collision behavior’s item array.

    Declaration

    Swift

    func addItem(_ item: UIDynamicItem)

    Objective-C

    - (void)addItem:(id<UIDynamicItem>)item

    Parameters

    item

    The dynamic item to add to the item array.

    Discussion

    You can add a dynamic item to one or more collision behaviors. For example, you can use two collision behaviors to specify that item A can collide with item B and that item C can collide with item D, but that items A and B ignore items C and D.

    There is no hard limit to the number of dynamic items you can add to a collision behavior. However, adding a large number of items might result in a performance impact. Be sure to test your behaviors on the device configurations you are targeting.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Initializes a collision behavior with an array of dynamic items.

    Declaration

    Swift

    init!(items items: [AnyObject])

    Objective-C

    - (instancetype)initWithItems:(NSArray *)items

    Parameters

    items

    The dynamic items that you want to participate in the collision behavior.

    Return Value

    The initialized collision behavior, or nil if there was a problem initializing the object.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Removes a specific dynamic item from the collision behavior.

    Declaration

    Swift

    func removeItem(_ item: UIDynamicItem)

    Objective-C

    - (void)removeItem:(id<UIDynamicItem>)item

    Parameters

    item

    The dynamic item that you want to remove.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • items items Property

    Returns the set of dynamic items you’ve added to the collision behavior. (read-only)

    Declaration

    Swift

    var items: [AnyObject] { get }

    Objective-C

    @property(nonatomic, readonly, copy) NSArray *items

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    func addBoundaryWithIdentifier(_ identifier: NSCopying, forPath bezierPath: UIBezierPath)

    Objective-C

    - (void)addBoundaryWithIdentifier:(id<NSCopying>)identifier forPath:(UIBezierPath *)bezierPath

    Parameters

    identifier

    An arbitrary identifier for the boundary you are adding.

    bezierPath

    An arbitrary Bezier path that specifies the collision boundary you are adding.

    The coordinate system and origin point for the path depend on how you’ve initialized the dynamic animator (that you’re adding the behavior to). See the overview in UIDynamicAnimator Class Reference for more information.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    func addBoundaryWithIdentifier(_ identifier: NSCopying, fromPoint p1: CGPoint, toPoint p2: CGPoint)

    Objective-C

    - (void)addBoundaryWithIdentifier:(id<NSCopying>)identifier fromPoint:(CGPoint)p1 toPoint:(CGPoint)p2

    Parameters

    identifier

    An arbitrary identifier for the boundary you are adding.

    p1

    The starting point for the boundary line segment.

    p2

    The ending point for the boundary line segment.

    Discussion

    This is a convenience method based on the addBoundaryWithIdentifier:forPath: method. The coordinate system and origin point for the p1 and p2 parameters depend on how you’ve initialized the dynamic animator (that you’re adding the behavior to). See the overview in UIDynamicAnimator Class Reference for more information.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • The set of boundary identifiers that you’ve added to the collision behavior. (read-only)

    Declaration

    Swift

    var boundaryIdentifiers: [AnyObject]? { get }

    Objective-C

    @property(nonatomic, readonly, copy) NSArray *boundaryIdentifiers

    Discussion

    If you haven’t added any boundary identifiers to the collision behavior, this property’s value is nil.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Returns a specified Bezier-path boundary.

    Declaration

    Swift

    func boundaryWithIdentifier(_ identifier: NSCopying) -> UIBezierPath?

    Objective-C

    - (UIBezierPath *)boundaryWithIdentifier:(id<NSCopying>)identifier

    Parameters

    identifier

    A boundary identifier that you’ve previously added to the collision behavior.

    Return Value

    A Bezier-path boundary.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    unowned(unsafe) var collisionDelegate: UICollisionBehaviorDelegate?

    Objective-C

    @property(nonatomic, assign, readwrite) id< UICollisionBehaviorDelegate > collisionDelegate

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    var collisionMode: UICollisionBehaviorMode

    Objective-C

    @property(nonatomic, readwrite) UICollisionBehaviorMode collisionMode

    Discussion

    To specify collisionMode, use one of the values in the UICollisionBehaviorMode enum. The default value is UICollisionBehaviorModeEverything.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    func removeAllBoundaries()

    Objective-C

    - (void)removeAllBoundaries

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Removes a specific collision boundary from the collision behavior.

    Declaration

    Swift

    func removeBoundaryWithIdentifier(_ identifier: NSCopying)

    Objective-C

    - (void)removeBoundaryWithIdentifier:(id<NSCopying>)identifier

    Parameters

    identifier

    The identifier of the boundary you want to remove.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    func setTranslatesReferenceBoundsIntoBoundaryWithInsets(_ insets: UIEdgeInsets)

    Objective-C

    - (void)setTranslatesReferenceBoundsIntoBoundaryWithInsets:(UIEdgeInsets)insets

    Parameters

    insets

    Insets to apply to the reference system’s bounds when defining the collision boundary.

    Discussion

    The result of using this method depends on how you’ve initialized the dynamic animator (of class UIDynamicAnimator) that you’ve added the collision behavior to. See the overview in UIDynamicAnimator Class Reference for a discussion of initialization options and modes for animators.

    Here is how the dynamic animator’s initialization impacts use of this method:

    • For a view-only dynamic animator, the reference bounds are those of the reference view

    • For a collection-view dynamic animator, the reference bounds are those of the collection view layout

    • For a dynamic-item dynamic animator, there are no reference bounds.

    For a collision behavior added to a view-only or collection-view dynamic animator, activate a reference-system-based collision boundary by setting the translatesReferenceBoundsIntoBoundary property to YEStrue.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    var translatesReferenceBoundsIntoBoundary: Bool

    Objective-C

    @property(nonatomic, readwrite) BOOL translatesReferenceBoundsIntoBoundary

    Discussion

    To specify a collision boundary based on the reference system, use the setTranslatesReferenceBoundsIntoBoundaryWithInsets: method.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    struct UICollisionBehaviorMode : RawOptionSetType { init(_ rawValue: UInt) init(rawValue rawValue: UInt) static var Items: UICollisionBehaviorMode { get } static var Boundaries: UICollisionBehaviorMode { get } static var Everything: UICollisionBehaviorMode { get } }

    Objective-C

    typedef NS_OPTIONS (NSUInteger, UICollisionBehaviorMode ) { UICollisionBehaviorModeItems = 1 << 0, UICollisionBehaviorModeBoundaries = 1 << 1, UICollisionBehaviorModeEverything = NSUIntegerMax };

    Constants

    • Items

      UICollisionBehaviorModeItems

      Specifies that the dynamic items, associated with the collision behavior, collide only with each other and not with specified collision boundaries.

      Available in iOS 7.0 and later.

    • Boundaries

      UICollisionBehaviorModeBoundaries

      Specifies that the dynamic items, associated with the collision behavior, collide only with specified collision boundaries and do not collide with each other.

      Available in iOS 7.0 and later.

    • Everything

      UICollisionBehaviorModeEverything

      Specifies that the dynamic items, associated with the collision behavior, collide with each other and with specified collision boundaries.

      This is the default collision behavior mode.

      Available in iOS 7.0 and later.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.