MaterialMotionCoreAnimation 2.0.0

MaterialMotionCoreAnimation 2.0.0

TestsTested
LangLanguage SwiftSwift
License Apache 2
ReleasedLast Release Feb 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Jeff Verkoeyen.



  • By
  • The Material Motion Authors

Core Animation for Material Motion (Swift)

This library provides a bridge between Core Animation and the Material Motion runtime.

Supported languages

  • Swift 3
  • Objective-C

Features

Tween uses Core Animation’s CAKeyframeAnimation to animate a CALayer property along an easing curve.

Use a Tween like you would use a CAKeyframeAnimation instance: provide a key path, duration, and an array of values.

let tweenBackgroundColor = Tween("backgroundColor",
                                 duration: animDuration,
                                 values: [UIColor.orange.cgColor, UIColor.lightGray.cgColor])
scheduler.addPlan(tweenBackgroundColor, to: myView)

Tween’s properties map to the following Core Animation properties:

Tween Core Animation
delay delay
duration duration
keyPath keyPath
keyPositions keyTimes
timingFunctions timingFunctions
values values

No other Core Animation properties are presently supported. View our filed feature requests to track progress on supporting additional functionality.

Installation

Usage

Import the framework:

@import MaterialMotionCoreAnimation;

You will now have access to all of the APIs.

Example apps/unit tests

Check out a local copy of the repo to access the Catalog application by running the following commands:

git clone https://github.com/material-motion/coreanimation-swift.git
cd coreanimation-swift
pod install
open MaterialMotionCoreAnimation.xcworkspace

Guides

  1. How to animate a property with a Tween plan
  2. How to commit Tween values to a layer

How to animate a property with a Tween plan

Code snippets:

In Objective-C:

MDMTween *tween = [[MDMTween alloc] initWithKeyPath:@"<#key path#>"
                                           duration:<#duration#>
                                             values:@[<#values...#>]];
[scheduler addPlan:tween to:<#Object#>];

In Swift:

let tween = Tween(<#key path#>, duration: <#duration#>, values: [<#values...#>])
scheduler.addPlan(tween, to: <#Object#>)

How to animate a property with just a destination value

Provide Tween with a single value and it will treat this value as the toValue of a CABasicAnimation. As per the Core Animation documentation:

Interpolates between the layer’s current value of the property in the render tree and `toValue’.

Code snippets:

In Objective-C:

MDMTween *tween = [[MDMTween alloc] initWithKeyPath:@"<#key path#>"
                                           duration:<#duration#>
                                             values:@[<#value#>]];
[scheduler addPlan:tween to:<#Object#>];

In Swift:

let tween = Tween(<#key path#>, duration: <#duration#>, values: [<#value#>])
scheduler.addPlan(tween, to: <#Object#>)

How to commit Tween values to a layer

We provide two helper APIs for committing the to/from value of a Tween plan to a given CALayer instance. This is most often used to commit the to value of the Tween to the layer so that the property does not appear to “snap back” upon completion of the animation.

Code snippets:

In Objective-C:

[tween commitFirstValueTo:<#CALayer#>];
[tween commitLastValueTo:<#CALayer#>];

In Swift:

tween.commitFirstValue(to: <#CALayer#>)
tween.commitLastValue(to: <#CALayer#>)

Contributing

We welcome contributions!

Check out our upcoming milestones.

Learn more about our team, our community, and our contributor essentials.

License

Licensed under the Apache 2.0 license. See LICENSE for details.