iOS Developer Library

Developer

UIKit Framework Reference UIDynamicItemBehavior Class Reference

Options
Deployment Target:

On This Page
Language:

UIDynamicItemBehavior

A dynamic item behavior represents a base dynamic animation configuration for one or more dynamic items. Each of its properties overrides a corresponding default value. More...

Inheritance


Conforms To


Import Statement


import UIKit @import UIKit;

Availability


Available in iOS 7.0 and later.
  • Adds a dynamic item to the dynamic item 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 dynamic item behaviors. For example, you could add a dynamic item to one dynamic item behavior to configure the item’s elasticity and to a second dynamic item behavior to configure its density. This is especially useful when you are defining custom, combined behaviors for your dynamic items.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

    See Also

    – removeItem:

  • Initializes a dynamic item 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 be subject to the dynamic item behavior.

    Return Value

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

    Discussion

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Removes a specific dynamic item from the dynamic item behavior.

    Declaration

    Swift

    func removeItem(_ item: UIDynamicItem)

    Objective-C

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

    Parameters

    item

    The dynamic item that you want to remove.

    Discussion

    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 dynamic item behavior. (read-only)

    Declaration

    Swift

    var items: [AnyObject] { get }

    Objective-C

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

    Discussion

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Adds a specified angular velocity to a dynamic item.

    Declaration

    Swift

    func addAngularVelocity(_ velocity: CGFloat, forItem item: UIDynamicItem)

    Objective-C

    - (void)addAngularVelocity:(CGFloat)velocity forItem:(id<UIDynamicItem>)item

    Parameters

    velocity

    The angular velocity, expressed in radians per second, that you want to add to the specified dynamic item. Default value is 0. Applying a negative value reduces the angular velocity by the specified amount.

    item

    The dynamic item whose angular velocity you want to increase (or decrease).

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Adds a specified linear velocity to a dynamic item.

    Declaration

    Swift

    func addLinearVelocity(_ velocity: CGPoint, forItem item: UIDynamicItem)

    Objective-C

    - (void)addLinearVelocity:(CGPoint)velocity forItem:(id<UIDynamicItem>)item

    Parameters

    velocity

    The linear velocity, expressed in points per second, that you want to add to the specified dynamic item. Default value is 0. Applying a negative value reduces the linear velocity by the specified amount.

    item

    The dynamic item whose linear velocity you want to increase (or decrease).

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Specifies whether rotation is allowed for the behavior’s dynamic items.

    Declaration

    Swift

    var allowsRotation: Bool

    Objective-C

    @property(readwrite, nonatomic) BOOL allowsRotation

    Discussion

    Default value is YEStrue. To disable rotation, set this property to NOfalse.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • The angular resistance for the behavior’s dynamic items.

    Declaration

    Swift

    var angularResistance: CGFloat

    Objective-C

    @property(readwrite, nonatomic) CGFloat angularResistance

    Discussion

    Valid range is 0 through CGFLOAT_MAX. The greater the value, the greater the angular damping and the faster rotation slows to a stop.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Returns the angular velocity for a specified dynamic item.

    Declaration

    Swift

    func angularVelocityForItem(_ item: UIDynamicItem) -> CGFloat

    Objective-C

    - (CGFloat)angularVelocityForItem:(id<UIDynamicItem>)item

    Parameters

    item

    The dynamic item whose angular velocity you want to get.

    Return Value

    The angular velocity of the specified dynamic item, in radians per second.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • density density Property

    The relative mass density of the behavior’s dynamic items.

    Declaration

    Swift

    var density: CGFloat

    Objective-C

    @property(readwrite, nonatomic) CGFloat density

    Discussion

    A dynamic item’s relative density, along with its size, determines its effective mass when it participates in UIKit Dynamics behaviors—including friction, collisions, pushes, and so on. For example, say you have two dynamic items with the same density but different sizes: item one is 100 x 100 points and item two is 100 x 200 points. In this example, item two has twice the effective mass of item one. In an elastic collision, these items exhibit a natural conservation of momentum according to their relative masses.

    A 100 x 100 point dynamic item with a density of 1.0, to which you apply a force (via a push behavior) of magnitude 1.0, accelerates at 100 points per second².

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • The amount of elasticity applied to collisions for the behavior’s dynamic items.

    Declaration

    Swift

    var elasticity: CGFloat

    Objective-C

    @property(readwrite, nonatomic) CGFloat elasticity

    Discussion

    Default value is 0.0. Valid range is from 0.0 for no bounce upon collision, to 1.0 for completely elastic collisions.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • friction friction Property

    The linear resistance for the behavior’s dynamic items when two slide against each other.

    Declaration

    Swift

    var friction: CGFloat

    Objective-C

    @property(readwrite, nonatomic) CGFloat friction

    Discussion

    Default value is 0.0, which corresponds to no friction. Use a value of 1.0 to apply strong friction. To apply an even stronger friction, you can use higher numbers.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • The linear resistance for the behavior’s dynamic items, which reduces their linear velocity over time.

    Declaration

    Swift

    var resistance: CGFloat

    Objective-C

    @property(readwrite, nonatomic) CGFloat resistance

    Discussion

    Default value is 0.0. Valid range is from 0.0 for no velocity damping, to CGFLOAT_MAX for complete velocity damping. If you set this property to 1.0, a dynamic item’s motion stops as soon as there is no force applied to it.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Returns the linear velocity for a specified dynamic item.

    Declaration

    Swift

    func linearVelocityForItem(_ item: UIDynamicItem) -> CGPoint

    Objective-C

    - (CGPoint)linearVelocityForItem:(id<UIDynamicItem>)item

    Parameters

    item

    The dynamic item whose linear velocity you want to get.

    Return Value

    The linear velocity of the specified dynamic item, in points per second.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.