Convenience types to configure two NSAnimation
s to loop infinitely.
SmoothAnimation
is anNSAnimation
that reports progress continuously instead of only reporting progress marks that'd result in jagged animations.AnimationLoop
handlesSmoothAnimation
callbacks to create a loop of two animations. You can configure the increase and decrease animation's durations and animation curves withAnimationLoop.LoopConfiguration
or through the convenience initializer.ValueAnimationLoop
wrapsAnimationLoop
, which progresses from 0.0 to 1.0, and instead forwards progress from 0.0 up to itsvalue
. You can use this to animate offsets from 0 to +100, or from 0 to -100, but not from -100 to +100. It always starts at 0.
This repository is Carthage compatible.
But the overhead of compiling these few classes into a Swift module is not worth the effort. This repository setup was thrown together to separate the sample app from the library code; I recommend to simply copy the relevant source code files into your project directly.
See the sample app for a simple "breathing" animation.
func setupAnimation() -> ValueAnimationLoop {
// Configure the animation to
// - start with an animation from 0...100 in 3 seconds,
// - then loop back from 100...0 in 2 seconds.
let loop = ValueAnimationLoop(
value: 100,
increaseDuration: 3.0,
increaseCurve: .easeInOut,
decreaseDuration: 2.0,
decreaseCurve: .easeInOut,
startWith: .increment)
loop.progressHandler = { [weak self] in self?.animateValueChange($0) }
return loop
}
func animateValueChange(_ value: CGFloat) {
// Change a view's position, size, color, whatever.
print(value)
}
Copyright (c) 2018 Christian Tietze. Distributed under the MIT License.