https://github.com/cleancocoa/loopinganimation
macOS NSAnimation loops
https://github.com/cleancocoa/loopinganimation
Last synced: 8 months ago
JSON representation
macOS NSAnimation loops
- Host: GitHub
- URL: https://github.com/cleancocoa/loopinganimation
- Owner: CleanCocoa
- License: mit
- Created: 2018-01-27T09:50:36.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-12-28T18:02:04.000Z (over 2 years ago)
- Last Synced: 2023-12-28T19:23:34.000Z (over 2 years ago)
- Language: Swift
- Size: 21.5 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LoopingAnimation




[](https://github.com/Carthage/Carthage)
Convenience types to configure two `NSAnimation`s to loop infinitely.
## Types
- `SmoothAnimation` is an `NSAnimation` that reports progress continuously instead of only reporting progress marks that'd result in jagged animations.
- `AnimationLoop` handles `SmoothAnimation` callbacks to create a loop of two animations. You can configure the **increase** and **decrease** animation's durations and animation curves with `AnimationLoop.LoopConfiguration` or through the convenience initializer.
- `ValueAnimationLoop` wraps `AnimationLoop`, which progresses from 0.0 to 1.0, and instead forwards progress from 0.0 up to its `value`. 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.
## Installation
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.**
## Example
See the sample app for a simple "breathing" animation.
```swift
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)
}
```
## Code License
Copyright (c) 2018 Christian Tietze. Distributed under the MIT License.