Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marty-suzuki/theanimation
Type-safe CAAnimation wrapper. It makes preventing to set wrong type values.
https://github.com/marty-suzuki/theanimation
animation carthage cocoapods ios macos tvos
Last synced: 13 days ago
JSON representation
Type-safe CAAnimation wrapper. It makes preventing to set wrong type values.
- Host: GitHub
- URL: https://github.com/marty-suzuki/theanimation
- Owner: marty-suzuki
- License: mit
- Created: 2018-05-12T05:17:25.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-20T18:44:40.000Z (almost 5 years ago)
- Last Synced: 2024-10-15T12:22:55.131Z (29 days ago)
- Topics: animation, carthage, cocoapods, ios, macos, tvos
- Language: Swift
- Homepage:
- Size: 325 KB
- Stars: 224
- Watchers: 11
- Forks: 14
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TheAnimation
TheAnimation is Type-safe CAAnimation wrapper.
![](./Images/basic_animation.png)
## Introduction
For example, if you want to animate `backgroundColor` with `CABasicAnimation`, you need to consider type because fromValue property and so on are `Any?`.
![](./Images/background_raw.png)
If you use `BasicAnimation of TheAnimation`, you can animate `backgroundColor` without considering type! (`AnimationKeyPaths.backgroundColor` is `AnimationKeyPath` type.)
![](./Images/background.png)
## Usage
The way of making an animation is almost similar `CAAnimation`.
But you need to use `animation.animate(in:)` method instead of using `layer.add(_:forKey:)`.```swift
let view = UIView()let animation = BasicAnimation(keyPath: .opacity)
animation.fromValue = 0
animation.toValue = 1
animation.duration = 1
animation.animate(in: view)
````animation.animate(in:)` returns `AnimaitonCanceller`. You can cancel an animation with it.
```swift
let canceller = animation.animate(in: view)
canceller.cancelAnimation()
```## Example
To run the example project, clone the repo, and open Example directory.
## Correspondence Table
| CAAnimation | TheAnimation |
| :-: | :-: |
| CAPropertyAnimation | PropertyAnimation |
| CABasicAnimation | BasicAnimation |
| CAKeyframeAnimation | KeyframeAnimation |
| CASpringAnimation | SpringAnimation |
| CATransition | TransitionAnimation |
| CAAnimationGroup | AnimationGroup |## Add new `AnimationKeyPath`
You can add `AnimationKeyPath` like this.
```swift
extension AnimationKeyPaths {
static let newKeyPath = AnimationKeyPath(keyPath: "abcd")
}
```## Handle animation did `Start` / `Stop`
You can handle animation did **Start** with `func setAnimationDidStart(handler:)`.
In addition, you can handle animation did **Stop** with `func setAnimationDidStop(handler:)`.```swift
let view = UIView()let animation = BasicAnimation(keyPath: .opacity)
animation.fromValue = 0
animation.toValue = 1
animation.duration = 1animation.setAnimationDidStart {
// do something
}animation.setAnimationDidStop { finished in
// do something
}animation.animate(in: view)
```## Requirements
- Xcode 9.3
- iOS 9 or greater
- tvOS 9 or greater
- macOS 10.11 or greater
- Swift 4.2 (since 0.3.0)## Installation
### Carthage
If you’re using [Carthage](https://github.com/Carthage/Carthage), simply add
TheAnimation to your `Cartfile`:```ruby
github "marty-suzuki/TheAnimation"
```### CocoaPods
TheAnimation is available through [CocoaPods](https://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod 'TheAnimation'
```## Author
marty-suzuki, [email protected]
## License
TheAnimation is available under the MIT license. See the LICENSE file for more info.