Contents

field(evaluationBlock:)

Creates and returns a field behavior object that applies an app-specified field to items.

Declaration

class func field(evaluationBlock block: @escaping (UIFieldBehavior, CGPoint, CGVector, CGFloat, CGFloat, TimeInterval) -> CGVector) -> Self

Parameters

  • block:

    The block to execute to compute the instantaneous force of the field on an item. This block returns a CGVector object that reflects the direction and magnitude of the force to apply. The block takes the following parameters:

    field

    The field behavior object being evaluated.

    position

    The point at which to compute the force value, in the reference coordinate system. The position corresponds to the location of an item in the field.

    velocity

    The velocity to be considered during evaluation of the force. Usually, this is the velocity of an item in the field. The vector reflects both the direction and magnitude of the velocity.

    mass

    The mass value to be used in any force computations. Use this value in fields where the applied forces vary with the mass of the object.

    charge

    The charge value to be used in any force computations. Use this value in fields where the applied forces vary with the charge of the object.

    deltaTime

    The amount of time that has passed since the last time the force value for this item was computed.

Return Value

A field behavior object that applies forces based on the custom algorithm you provided.

Discussion

Use this method to define a custom field for your app. The block you provide is called many times during the course of animations, so your implementation should be reasonably fast. Use the provided field object to retrieve values associated with the field itself, such as the field’s position and strength. The other parameters reflect information about the dynamic item affected by the field.

See Also

Getting the field behaviors