• This repository has been archived on 05/Jan/2020
  • Stars
    star
    1,892
  • Rank 23,740 (Top 0.5 %)
  • Language
    Swift
  • License
    MIT License
  • Created about 9 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A DSL to make animation easy on iOS with Swift.

This project is highly inspired by JHChainableAnimations, If you project is developed with Objective-C, use JHChainableAnimations instead.

With DKChainableAnimationKit

Using DKChainableAnimationKit, you do not need to write the extra parentheses.

view.animation.makeScale(2.0).spring.animate(1.0)

Installation with CocoaPods

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like DKNightVersion in your projects. See the Get Started section for more details.

Podfile

use_frameworks!

pod "DKChainableAnimationKit", "~> 2.0.0"

Installation with Carthage

Carthage is a depency manager for Objectiv-C and Swift.

Cartfile

github "Draveness/DKChainableAnimationKit"

Usage

Import DKChainableAnimationKit in proper place.

import DKChainableAnimationKit

DKChainableAnimationKit is designed to be extremely easy to use. First call animation method on UIView instance, and then add the animation you want followed by a animate(t) method.

view.animation.moveX(100.0).animate(1.0)

Animating

Chainable properties or functions like moveX(x) must come between the animate(duration) function.

view.animation.moveX(100.0).animate(1.0)

If you want mutiple animation at one time.

view.animation.moveX(100.0).moveY(100.0).animate(1.0)

This will move the view 100 point right and 100 point down at the same time. Order is not important.

Chaining Animations

To chain animations separate the chains with the thenAfter(duration) function.

view.animation.moveX(100.0).thenAfter(1.0).makeScale(2.0).animate(2.0)

This will move the view for one second and after moving, it will scale for two seconds.

Animation Effects

To add animation effect, call the effect method after the chainable property you want it to apply it.

Below is an example of moving a view with a spring effect.

view.animation.moveX(10).spring.animate(1.0)

If you add two animation effect, the first will be cancel out.

view.animation.moveX(10).spring.bounce.animate(1.0)
// The same as view.animation.moveX(10).bounce.animate(1.0)

Anchoring

To anchor your view call an anchoring method at some point in an animation chain. And if you add two anchoring property, the first will be cancel like effects.

view.animation.rotate(180).anchorTopLeft.thenAfter(1.0).rotate(90).anchorCenter.animanimation

Delay

To delay an animation call the wait(time) or delay(time) chainable function.

view.animation.moveXY(100, 40).wait(0.5).animate(1.0)
view.animation.moveXY(100, 40).delay(0.5).animate(1.0)
delay

This will move the view after 0.5 second delay.

Completion

If you want to run code after an animation finishes, you are supposed to set the animationCompletion property or call animateWithCompletion(t, completion) function.

view.animation.makeX(0).animateWithCompletion(1.0, {
    println("Animation Done")
})

This is the same as

view.animation.animationCompletion = {
    println("Animation Done")
}
view.animation.makeX(0).animate(1.0)

And also the same as

view.animation.makeX(0).animate(1.0).animationCompletion = {
    println("Animation Done")
}

Bezier Paths

You can also animate a view along a UIBezierPath. Call bezierPathForAnimation method first and then add points or curves to it and us it in a chainable property.

let path = view.animation.bezierPathForAnimation()
path.addLintToPoint(CGPoint(x: 30, y: 40))
view.animation.moveOnPath(path).animate(1.0)

Animation effects does not work on path movement.


Chainable Properties

moveX(100.0)
moveY(100.0)
moveWidth(100.0)
moveHeight(100.0)
moveXY(100.0, 100.0)
makeX(100.0)
makeY(100.0)
makeOrigin(100.0, 100.0)
makeCenter(100.0, 100.0)
makeWidth(100.0)
makeHeight(100.0)
makeSize(100.0, 100.0)
makeFrame(rect) // let rect: CGRect
makeBounds(rect) // let rect: CGRect
makeScale(2.0)
makeScaleX(2.0)
makeScaleY(2.0)
makeOpacity(0.0)
makeBackground(purple) // let purple: UIColor
makeBorderColor(red) // let red: UIColor
makeBorderWidth(10.0)
makeCornerRadius(25.0)

To Do

  • Support OS X
  • Support Swift 2.0

Contact

  • If you have some advice open an issue or a PR.
  • Email [Draveness](mailto: [email protected])

License

DKChainableAnimationKit is available under the MIT license. See the LICENSE file for more info.

More Repositories

1

analyze

Draven's Blog
Objective-C
8,083
star
2

DKNightVersion

Manage Colors, Integrate Night/Multiple Themes. (Unmaintained)
Objective-C
3,557
star
3

NightNight

Elegant way to integrate night mode to swift projects
Swift
777
star
4

Typeset

Deal with AttributedString efficiently
Objective-C
450
star
5

RbSwift

Extensions for Swift with hundreds of handy methods.
Swift
320
star
6

go-internal

《Go 语言设计与实现》示例代码
Go
258
star
7

Ouroboros

🐍 ObjectiveC library for magical scroll interactions.
Objective-C
149
star
8

blog-comments

面向信仰编程
140
star
9

ATProperty

☀️ Create @property with shortcut
Objective-C
136
star
10

proxier

A better approach to expose application in Kubernetes.
Go
108
star
11

linux-archive

Linux archive for studying the process scheduler. 调度系统设计精要 http://draveness.me/system-design-scheduler
C
87
star
12

JSONCop

A better way to deal with JSON parsing in Swift.
Ruby
30
star
13

Mineral

A library used to separate concerns from the original UIKit framework.
Swift
29
star
14

ChainableKit

Chainable UIKit in Objective-C
Objective-C
27
star
15

oceanbook

A Modern Matching Engine without documentation YET [alpha]
Go
25
star
16

Crotalus

Elegant approach to create AttributedString in swift
Swift
19
star
17

SpaceShuttle

🚀 A library manages Inter-View value passing
Objective-C
13
star
18

go-utils

Go
12
star
19

OKObserver

A lightweight wrapper for KVO, bind view and model easily
Objective-C
12
star
20

draveness

10
star
21

git-ignore

Rust
3
star
22

tmpwatch-controller

Dockerfile
2
star
23

gitbook-plugin-gitalk

JavaScript
2
star
24

Daytabase

An key/value store database built atop sqlite
Swift
1
star