anim

final public class anim: NSObject

anim is an animation library written in Swift with a simple, declarative API in mind.

// moves box to 100,100 with default settings
anim {
    self.box.frame.origin = CGPoint(x:100, y:100)
    }
    // after that, waits 100 ms
    .wait(100)
    // moves box to 0,0 after waiting
    .then {
        self.box.frame.origin = CGPoint(x:0, y:0)
    }
    // displays message after all animations are done
    .callback {
        print("Just finished moving 📦 around.")
}

It supports a bunch of easing functions and chaining multiple animations. It’s a wrapper on Apple’s UIViewPropertyAnimator on its core.

  • Default settings for animation. This is being copied to promise for each animation.

    Declaration

    Swift

    public static var defaultSettings = animSettings()
  • Creates initial animation promise, with settings.

    Declaration

    Swift

    public convenience init(_ closureWithSettings: @escaping (inout animSettings) -> (animClosure))

    Parameters

    closure

    Exposes settings values to block, and expects returning animation block.

  • Creates initial animation promise.

    Declaration

    Swift

    public convenience init(_ closure: @escaping animClosure)

    Parameters

    closure

    Animation block.

  • Stops animation and promise chain.

    Declaration

    Swift

    public func stop()
  • Creates initial animation promise for NSLayoutConstraint animations, with settings.

    Declaration

    Swift

    public convenience init(constraintParent: View,
                            _ closureWithSettings: @escaping (inout animSettings) -> animClosure)

    Parameters

    constraintParent

    Top parent where constraints reside.

    closureWithSettings

    Exposes settings values to block, and expects returning animation block.

  • Creates initial animation promise for NSLayoutConstraint animations.

    Declaration

    Swift

    public convenience init(constraintParent: View, _ closure: @escaping animClosure)

    Parameters

    constraintParent

    Top parent where constraints reside.

    closure

    Animation block.

  • Creates a new promise for NSLayoutConstraint animations with settings, chained to the previous one.

    Declaration

    Swift

    public func then(constraintParent: View,
                     _ closureWithSettings: @escaping (inout animSettings) -> animClosure) -> anim

    Parameters

    constraintParent

    Top parent where constraints reside.

    closureWithSettings

    Exposes settings values to block, and expects returning animation block.

    Return Value

    Newly created promise.

  • Creates a new promise for NSLayoutConstraint animations with settings, chained to the previous one.

    Declaration

    Swift

    public func then(constraintParent: View, _ closure: @escaping animClosure) -> anim

    Parameters

    constraintParent

    Top parent where constraints reside.

    closure

    Animation block.

    Return Value

    Newly created promise.

  • Creates a new animation promise with settings, chained to the previous one.

    Declaration

    Swift

    public func then(_ closureWithSettings: @escaping (inout animSettings) -> animClosure) -> anim

    Parameters

    closure

    Exposes settings values to block, and expects returning animation block.

    Return Value

    Newly created promise.

  • Creates a new animation promise, chained to the previous one.

    Declaration

    Swift

    public func then(_ closure: @escaping animClosure) -> anim

    Parameters

    closure

    Animation block.

    Return Value

    Newly created promise.

  • Creates a promise only waits before running next promise.

    Declaration

    Swift

    public func wait(_ seconds: TimeInterval) -> anim

    Parameters

    milliseconds

    Milliseconds to wait.

    Return Value

    Newly created promise.

  • Creates a promise only calls a block before running next promise.

    Declaration

    Swift

    public func callback(_ closure: @escaping animClosure) -> anim

    Parameters

    closure

    Block to be runned.

    Return Value

    Newly created promise.