Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/onurersel/anim
Swift animation library for iOS, tvOS and macOS.
https://github.com/onurersel/anim
animation animation-library carthage cocoapods ios macos swift-animation swift4 tvos
Last synced: about 1 month ago
JSON representation
Swift animation library for iOS, tvOS and macOS.
- Host: GitHub
- URL: https://github.com/onurersel/anim
- Owner: onurersel
- License: mit
- Created: 2016-01-15T12:26:07.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2021-03-09T04:35:34.000Z (almost 4 years ago)
- Last Synced: 2024-10-30T08:17:59.348Z (about 1 month ago)
- Topics: animation, animation-library, carthage, cocoapods, ios, macos, swift-animation, swift4, tvos
- Language: Swift
- Homepage:
- Size: 5.49 MB
- Stars: 569
- Watchers: 14
- Forks: 46
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - anim - An animation library for iOS with custom easings and easy to follow API. (UI / Animation)
- awesome-ios-star - anim - An animation library for iOS with custom easings and easy to follow API. (UI / Animation)
README
-----
[![CocoaPods](https://img.shields.io/cocoapods/v/anim.svg)](https://cocoapods.org/pods/anim)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Build Status](https://travis-ci.org/onurersel/anim.svg?branch=master)](https://travis-ci.org/onurersel/anim)
[![codecov.io](https://codecov.io/github/onurersel/anim/coverage.svg?branch=master)](https://codecov.io/github/onurersel/anim?branch=master)
[![codebeat badge](https://codebeat.co/badges/67e95eda-c701-43d0-921c-541a427750bd)](https://codebeat.co/projects/github-com-onurersel-anim)`anim` is an animation library written in Swift with a simple, declarative API in mind.
```swift
// moves box to 100,100 with default settings
anim {
self.box.frame.origin = CGPoint(x:100, y:100)
}
// after that, waits 100 ms
.wait(0.1)
// moves box to 0,0 after waiting
.then {
self.box.frame.origin = CGPoint(x:0, y:0)
}
// displays message after all animations are done
.callback {
print("Just finished moving 📦 around.")
}
```It supports a bunch of easing functions and chaining multiple animations. It's a wrapper on Apple's `UIViewPropertyAnimator` on its core, and falls back to `UIView.animate` on versions before iOS and tvOS 10.
It uses `NSAnimationContext` on macOS.#### Examples
Example projects are available at `examples/` folder and as targets on XCode project.
---
#### Cocoapods
```ruby
pod 'anim'
```#### Carthage
```ogdl
github "onurersel/anim"
```#### Manually
Or simply drag the swift files inside `src/` folder into your project.
---
For complete documentation, visit [http://onurersel.github.io/anim/](http://onurersel.github.io/anim/).
Initialize animations with `anim` constructor.
```swift
// Initialize with default settings
anim {
// animation block
}
``````swift
// or initialize with it's own settings
anim { (settings) -> (animClosure) in
settings.delay = 1
settings.duration = 0.7
settings.ease = .easeInOutBackreturn {
// animation block
}
}
``````swift
// or initialize layout constraint animations just by passing the parent view
anim(constraintParent: self.view) {
// animation block
}anim(constraintParent: self.view) { (settings) -> (animClosure) in
// settings...
return {
// animation block
}
}// you don't need to call layoutIfNeeded() before or inside the
// animation blocks, it's handled by anim
//
// for example to update constant value of a constraint,
// you can just change it inside the animation block
let width: NSLayoutConstraint //...
anim(constraintParent: self.view) {
width.constant = 100 // new value
}
// that's it!
```Chain animations with `then` function.
```swift
anim {}
.then{
// next animation block
}
``````swift
anim {}
.then { (settings) -> animClosure in
settings.duration = 1
return {
// next animation block
}
}
``````swift
anim {}
.then(constraintParent: self.view) {
// chaining constraint animations
}
.then(constraintParent: self.view) { (settings) -> animClosure in
settings.duration = 1
return {
// next animation block for constraints
}
}
```Wait between animation steps with `wait` function.
```swift
anim{}.wait(0.25).then{} //...
```Insert callbacks between animation steps with `.callback` function.
```swift
anim{}
.callback {
// custom block
}
.then{} //...
```Stop animations with `stop` function.
```swift
let animation = anim{}.then{} // ...
animation.stop()
```#### Default settings
You can change default animation settings through `anim.defaultSettings` property.
```swift
anim.defaultSettings.ease = .easeInOutCubic
```#### Easing
`anim.Ease` exposes a bunch of easing options.
---
`anim` is released under the MIT license. See LICENSE for details.