Moveable

@MainActor
public protocol Moveable : AnyObject

This protocol declares methods and properties that must be adopted by custom motion classes in order to participate in the MotionMachine ecosystem. All standard MotionMachine motion classes conform to this protocol.

  • Stops a motion that is currently moving. (required)

    Remark

    When this method is called, a motion should only enter a stopped state if it currently moving.

    Declaration

    Swift

    @MainActor
    func stop()
  • Starts a motion that is currently stopped. (required)

    Remark

    This method can be chained when initializing the object.

    Note

    When this method is called, a motion should only start moving if it is stopped.

    Declaration

    Swift

    @discardableResult
    @MainActor
    func start() -> Self

    Return Value

    A reference to the Moveable instance; used to method chain initialization methods when the Moveable instance is created.

  • Pauses a motion that is currently moving. (required)

    Remark

    When this method is called, a motion should only enter a paused state if it is currently moving.

    Declaration

    Swift

    @MainActor
    func pause()
  • Resumes a motion that is currently paused. (required)

    Remark

    When this method is called, a motion should only resume moving if it is currently paused.

    Declaration

    Swift

    @MainActor
    func resume()
  • Resets a motion to its initial state. Custom classes implementing this method must reset all relevant properties, including totalProgress. (required)

    Remark

    This method is used by Moveable collection classes to properly reset child motions for new movement cycles and when starting a motion again using the start method.

    Declaration

    Swift

    @MainActor
    func reset()
  • A MotionState enum which represents the current state of the motion operation. This state should be updated by the class implementing this protocol.

    Declaration

    Swift

    @MainActor
    var motionState: MotionState { get }
  • A Boolean which determines whether a motion operation, when it has moved to the ending value, should move from the ending value back to the starting value.

    Remark

    When set to true, the motion plays in reverse after completing a forward motion. In this state, a motion cycle represents the combination of the forward and reverse motions. The default value should be false.

    Declaration

    Swift

    @MainActor
    var reversing: Bool { get set }
  • A value between 0.0 and 1.0, which represents the current overall progress of a motion. This value should include all reversing and repeat motion cycles. (read-only)

    Declaration

    Swift

    @MainActor
    var totalProgress: Double { get }
  • Provides a delegate for sending MoveableStatus updates from a Moveable object. This property is used by Moveable collection classes. Any custom Moveable classes must send status updates using this delegate.

    Warning

    This delegate is only used by Moveable objects to communicate with other Moveable objects. End-users should not assign their own delegate to this property. If you need status updates for a Moveable object, please use the provided callback closures.

    Declaration

    Swift

    @MainActor
    var updateDelegate: MotionUpdateDelegate? { get set }
  • This method is called to prompt a motion class to update its current movement values.

    Declaration

    Swift

    @MainActor
    func update(withTimeInterval currentTime: TimeInterval)

    Parameters

    currentTime

    A timestamp that can be used in easing calculations.

  • cleanupResources() Default implementation

    Calling this method on the conforming object should cleanup any resources to prepare for deallocation.

    Default Implementation

    Declaration

    Swift

    @MainActor
    func cleanupResources()