Latest 1.0.0
Homepage https://github.com/j-h-a/Animation
License MIT
Platforms ios 10.0

A framework for performing animations on any properties using custom curves.

Requires: Xcode 8, Swift 3.0

Overview

  • Trigger animations that call a closure repeatedly (in sync with the display refresh)
    for a dspecified duration, from which you can update on-screen objects.
  • Cancel/overwrite triggered animations by their identifier.
  • Add/remove instances conforming to the Animatable protocol to a list so they will
    receive an update call in sync with the display refresh.
  • Use the convenient interpolation operators and Curve classes to simplify your code.
  • Make your own curves using CompositeCurve or by implementing the Parametric protocol.

Getting Started

You can install and use this Framework with Cocoapods, or by manually adding the
Animation project into your workspace and updating the build settings.

Installation (Cocoapods)

Requires: Cocoapods 1.1.0 or higher

Add the dependency to your Podfile:

pod 'Animation', '~> 1.0'

Tell Cocoapods to retrieve the dependencies and include them into your workspace:

pod install

Installation (Manually managed)

  1. Clone the animation repository as a submodule of your project repository, or otherwise
    get the code and include it in your project.
  2. Include the Animation.xcproject project into your Workspace.
  3. Embed/link the Animation.framework with your targets in the target/build settings.

Using Animations

Import the module:

import Animation

Perform fire-and-forget animations:

let startPoint = CGPoint(x: 10, y: 10)
let endPoint = CGPoint(x: 100, y: 100)
let startColor = UIColor.black
let endColor = UIColor.red

Animation.animate(identifier: "example", duration: 0.5,
    update: { (progress) -> Bool in
        myView.center = startPoint <~~ Curve.easeInEaseOut[progress] ~~> endPoint
        myView.backgroundColor = startColor <~~ progress ~~> endColor
        return true
    })

What’s going on:

The Animation.animate(identifier:duration:update:completion:) function starts an animation
immediately, calling your update code repeatedly (in sync with the display refresh) for the
specified duration. Within the update closure, a UIView instance is updated by changing its
center and backgroundColor properties. You can perform any calculations, and update
whatever properties you like, including ones that aren’t normally animatable using UIKit
animnations. The interpolation operators are used to get an interpolated value between the
start and end values, for example 10.0 <~~ 0.1 ~~> 20.0 would return a value 0.1 of the way
from 10.0 to 20.0, i.e. 11.0. The progress parameter is used to perform linear interpolation
of the backgroundColor and the Curve.easeInEaseOut object is used to convert the linear
progress into an ease-in-ease-out curve to animate the position.

Using Animatables

Import the module:

import Animation

Adopt the Animatable protocol:

class MyAnimatableClass: Animatable {

Conform to the Animatable protocol:

func update(by timeInterval: Double) {
    // Do whatever you want, using timeInterval to calculate the new position of things
}

Add your instance to receive updates:

Animation.add(animatable: self)

Latest podspec

{
    "name": "Animation",
    "version": "1.0.0",
    "summary": "A Swift 3 framework for performing animations on any properties using custom curves",
    "description": "This Animation framework allows you to have more control over on-screen animations,nor indeed anything you want to change the value of over time. For each animationnyou provide a closure which is called repeatedly with a progress value, and from herenyou can set whatever properties you want. You're not restricted to the 'animatable'nproperties, and you can use the helper curve classes and interpolation operators tonmake your code very small, clear, and concise. With the curve classes, you cannconstruct custom curves and use them to control the motion of your animations as ansingle fire-and-forget call to trigger the animation, instead of chaining togethernsecondary and tiertary animations from the completion blocks.nnIn addition to the triggerable animations, you can adopt the Animatable protocol innany of your classes, and add them to start receiving updates. This allows you to getnconstant callbacks in sync with the screen refresh, so that you can apply any motionneffects you want. You can remove your Animatable so that it no longer receivesnupdates at any time, but if you forget to remove it don't worry - the Animationnframework only keeps a weak reference to it, and will automatically remove it whennyour instance goes away.",
    "homepage": "https://github.com/j-h-a/Animation",
    "license": {
        "type": "MIT",
        "file": "LICENSE.md"
    },
    "authors": "Jay Abbott",
    "platforms": {
        "ios": "10.0"
    },
    "source": {
        "git": "https://github.com/j-h-a/Animation.git",
        "tag": "1.0.0"
    },
    "source_files": "Animation"
}

Pin It on Pinterest

Share This