Seamless.framework
for OSX and libSeamless.a
for iOS enhance Core Animation with additive negative delta animation.
It adds simple animation smoothing or custom timing determined by blocks,
to instances of CABasicAnimation
with an extension to CATransaction
,
or on instances of a CAPropertyAnimation
subclass called SeamlessAnimation
.
It is meant to be used where implicit animation is appropriate,
and is especially useful for the NSAnimatablePropertyContainer
Protocol (NSView
animation) which requires implicit animation.
Animations are declared with absolute values,
but run relative to the underlying model value by animating from the old model value minus the new model value,
to a destination value of zero.
This is the best technique for responding to rapid user events.
Uses additive, enables negative delta animation, uses previous values instead of presentation, uses fillMode of kCAFillModeBackwards, affects animation key naming behavior,
Keyframes are used to emulate a custom timing function. Without timing block this has no effect. If not set, default is 100.
Set the block used for timing of animations in current transaction.
Sole argument is a double
between 0 and 1.
Return value is a double
that can also be below 0 and above 1.
If not set, animations use a CAMediaTimingFunction
with control points 0.5, 0.0, 0.5, 1.0 for simple smoothing.
Additive or negative delta behavior is not implied with this.
Timing is emulated by replacing animations with instances of CAKeyframeAnimation behind the scenes. Animated values must be one of transform, rect, size, point, float, or double.
This gives a nice elastic wobble and is based on math from Matt Gallager's excellent Animation Acceleration.
[CATransaction setAnimationDuration:3.0];
[CATransaction setSeamlessNegativeDelta:YES];
[CATransaction setSeamlessTimingBlock:^ (double progress) {
double omega = 20.0;
double zeta = 0.5;
double beta = sqrt(1.0 - zeta * zeta);
return 1 - 1 / beta * expf(-zeta * omega * progress) * sinf(beta * omega * progress + atanf(beta / zeta));
}];
theFirstLayer.position = CGPointMake(100,100);
theSecondLayer.transform = CATransform3DMakeRotation(M_PI_2, 0, 0, 1);
Overrides transaction value, with the same effect.
Overrides transaction value, with the same effect.
Overrides transaction value, with the same effect.
Inherits from CABasicAnimation
.
Default values differ from CABasicAnimation:
additive = YES,
fillMode = kCAFillModeBackwards,
seamless = YES,
fromValue = old minus new,
toValue = zero
Optional. The layer's previous model value or what it is supposed to appear to be. You define the value absolutely but behind the scenes it is converted to a relative old minus new.
Optional. The layer's current ("new") model value or what it is supposed to appear to be. Behind the scenes, the actual animation destination is zero.
typedef double(^SeamlessTimingBlock)(double);
Released under the BSD License. Inslerpolate.c is adapted from WebKit source and released under a separate license.
Add a key naming behavior property and enum, which is needed if you want to retrieve animations for copying and applying them to newly inserted layers.
Because completely new animations are created and replace the passed in animations, arbitrary animation dictionaries and animation delegates are not respected. I should hold on to the original animation for this.
Documentation unfinished.
Need iOS examples.