TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | Apache 2 |
ReleasedLast Release | Feb 2017 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✗ |
Maintained by Jeff Verkoeyen.
This library provides a bridge between Core Animation and the Material Motion runtime.
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.
Import the framework:
@import MaterialMotionCoreAnimation;
You will now have access to all of the APIs.
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
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#>)
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#>)
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#>)
We welcome contributions!
Check out our upcoming milestones.
Learn more about our team, our community, and our contributor essentials.
Licensed under the Apache 2.0 license. See LICENSE for details.