Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pimcoumans/animationplanner
Chain multiple UIView animations without endless closure nesting
https://github.com/pimcoumans/animationplanner
animation swift
Last synced: 20 days ago
JSON representation
Chain multiple UIView animations without endless closure nesting
- Host: GitHub
- URL: https://github.com/pimcoumans/animationplanner
- Owner: PimCoumans
- License: apache-2.0
- Created: 2022-06-01T21:30:32.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-14T14:45:14.000Z (5 months ago)
- Last Synced: 2024-10-14T20:09:26.014Z (about 1 month ago)
- Topics: animation, swift
- Language: Swift
- Homepage:
- Size: 312 KB
- Stars: 107
- Watchers: 3
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FPimCoumans%2FAnimationPlanner%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/PimCoumans/AnimationPlanner)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FPimCoumans%2FAnimationPlanner%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/PimCoumans/AnimationPlanner)![Animation Planner logo](Assets/AnimationPlanner.png)
# AnimationPlannerโ Chain multiple `UIView` animations without endless closure nesting. Create your animation sequence all on the same indentation level using a clear, concise syntax.
๐คน Used for all exuberant animations in [OK Video ๐ฒ](https://okvideo.app/download)
๐ Check out the [documentation](https://swiftpackageindex.com/PimCoumans/AnimationPlanner/main/documentation/animationplanner) to get up to speed, or read on to see a little example.
## How do I plan my animations?
๐ฆ Add `AnimationPlanner` to your project (using Swift Package manager) and start typing `AnimationPlanner.plan` to embark on your animation journey. Like whatโs happening in the code below.
```swift
AnimationPlanner.plan {
Animate(duration: 0.32, timingFunction: .quintOut) {
view.alpha = 1
view.center.y = self.view.bounds.midY
}
Wait(0.2)
Animate(duration: 0.32) {
view.transform = CGAffineTransform(scaleX: 2, y: 2)
view.layer.cornerRadius = 40
view.backgroundColor = .systemRed
}.timingFunction(.quintOut)
Wait(0.2)
AnimateSpring(duration: 0.25, dampingRatio: 0.52) {
view.backgroundColor = .systemBlue
view.layer.cornerRadius = 0
view.transform = .identity
}
Wait(0.58)
Animate(duration: 0.2) {
view.alpha = 0
view.transform = .identity
view.frame.origin.y = self.view.bounds.maxY
}.timingFunction(.circIn)
}.onComplete { finished in
view.removeFromSuperview()
}
```The above code results in the following animation sequence. For more examples see the [Sample App](Sample%20App/AnimationPlanner-Sample/ViewController.swift) available when cloning the repo.
_**Note:** The example uses [custom extension methods](Sources/AnimationPlanner/Extensions/CAMediaTimingFunction.swift) on `CAMediaTimingFunction`, included with the framework_
## Installation
### ๐ Adding AnimationPlanner as a package dependency
1. Go to `File` -> `Add Packages`
3. Paste `https://github.com/PimCoumans/AnimationPlanner` in the search bar and click on "Add Package"
4. Select the target(s) in which you want to use AnimationPlanner### ๐ฆ Swift Package Manager
Manually add AnimationPlanner as a package dependency in `package.swift`, by updating your package definition with:
```swift
dependencies: [
.package(name: "AnimationPlanner", url: "https://github.com/PimCoumans/AnimationPlanner.git", .branch("main"))
],
```And updating your targetโs dependencies property with `dependencies: ["AnimationPlanner"]`
## ๐ฎ Future plans
While this API removes a lot of unwanted nesting in completion closures when using traditional `UIView.animate...` calls, a project is never finished and for future versions I have the following plans:
- Remove usage of inaccurate `DispatchQueue.main.asyncAfter`, currently used to add delays for non-`UIView` animations or bridging gaps between steps.
- Maybe even allow this package to play more nicely with SwiftUI? No idea what that would look like though, any ideas?
Got any feedback or suggestions? Please let me know! โ๐ปโ [twitter.com/pimcoumans](https://twitter.com/pimcoumans)