A DSL to make animation easy on iOS with Swift.

Overview

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.

Comments
  • Dynamic Framework (& Carthage support)

    Dynamic Framework (& Carthage support)

    Currently, DKChainableAnimationKit does not have a framework target. Instead the classes are in a project shared with an iOS sample app. This setup is prohibits the use of carthage as a depency manager. Also, imho the frameworks classes and the sample project should be separated.

    I went ahead and separated everything into two projects. There now is one project for the actual framework and another one for the sample app. I also added a workspace containing both projects.

    In addition I updated the .gitignore to also ignore OS X files like .DS_Store and fixes a spelling mistake (DKChainaleAnimationKit.swift --> DKChainableAnimationKit.swift).

    opened by mathiasnagler 7
  • not working xcode 7.3

    not working xcode 7.3

    HI, I am using xocde 7.3. After installing pod file the xcode shows many syntax errors in the follwing swift files DKChainableAnimationKit+Anchor.swift, DKChainableAnimationKit.swift, DKKeyFrameAnimation.swift

    opened by Aravind6 6
  • Swift 2

    Swift 2

    Updates DKChainableAnimationKit to the new Swift 2 using Xcode 7 beta1.

    I suggest to keep this around as a separate branch feature/swift-2 and not merge it into master, as it breaks compatibility with Xcode 6 and can only be build using beta software. However, to use DKChainableAnimationKit with the new Xcode and iOS 9 this change is required. Once Xcode 7 leaves beta stage, the branch can then be merged.

    opened by mathiasnagler 6
  • Animating Background Color Crashing

    Animating Background Color Crashing

    When you use the method makeBackground with a basic default monotone colors that are created using the UIColor convenience methods, like UIColor.black, UIColor.white, UIColor.gray, etc., the app crashes because the way it finds the color components. In Swift 3 with iOS 10 these methods return a color with only two components, a darkness value and an alpha value. This does not cause an issue with colors like UIColor.red or UIColor(red: 0.0, blue: 0.0, green: 0.0, alpha: 1.0) however. I will be able to make a fix if you'd like.

    opened by CharlesMassry 4
  • Podfile + Xcode 8

    Podfile + Xcode 8

    pod "DKChainableAnimationKit", "~> 1.6.1"

    But it downloads something old, however version is 1.6.1. Swift 2.2 alike. Cleaned cached in cocoapods, but didn't help.

    opened by piv199 3
  • prevents crash if view was not set

    prevents crash if view was not set

    I had created my custom repeat logic and noticed that when I was repeating an animation group I would get this crash because the view at this stage is nil.

    opened by apouche 3
  • Suggestion at SnapKit

    Suggestion at SnapKit

    Great library (and thanks to @jhurray for the original objc). I thought you might be interested in this suggestion: https://github.com/SnapKit/SnapKit/issues/93

    enhancement 
    opened by cannyboy 3
  • I had to add

    I had to add "import DKChainableAnimationKit" to make it work.

    Great library!

    Whiteout the line "import DKChainableAnimationKit", I got the error "X doesn't have a member named animation".

    It might be nice to add this to the documentation, or am I doing something wrong? I installed the library via Cocoapods.

    opened by samuelbeek 2
  • Fix Carthage Build

    Fix Carthage Build

    In my previous pull request #5 something went wrong with the run schemes. Thus, when carthage tried to build the framework an error occurred.

    I fixed the error with the schemes so now the project can be build via carthage. I tried building it using different versions of carthage and it worked flawlessly every time.

    I also updated the README.md to contain carthage support and bumped CURRENT_PROJECT_VERSION to 1.3.

    Sorry for the problems with my previous pull request. I am confident that everything is fixed now.

    opened by mathiasnagler 1
  • Fixed make background to work with monotone colors in iOS 10

    Fixed make background to work with monotone colors in iOS 10

    Converts the 2 components of the monotone colors convenience initializers to 4 while keeping the same behavior when using other initializers. fixes #24

    opened by CharlesMassry 0
  • Swift 3.0

    Swift 3.0

    I used the swift converter in Xcode. That fixed most of the issues, there where some manual ones like casting the DKKeyFrameAnimation's fromValue and toValue assignment, adding the @discardableResult directive to the public animation functions (animate and animateWithCompletion) because this now produces a warning. Unfortunately you can't add the @discardarbleResult directive to properties so I simply used the _ = to suppress the warnings. There were a couple of other minor things here and there. Fixed the iOS Example and everything seems to be working.

    opened by CharlesMassry 0
  • Doesn't compile in XCode 9.2 with Swift 4

    Doesn't compile in XCode 9.2 with Swift 4

    Hi! I installed DKChainableAnimationKit through CocoaPods and unfortunately it doesn't compile. I keep getting this error "Missing argument for parameter #1 in call" and three warnings. Please see the attached screenshot

    screen shot 2017-12-14 at 3 10 11 pm

    opened by da-na 2
  • Animation trouble using Timer

    Animation trouble using Timer

    Basically I have a sidemenu that I am using DKChainableAnimationKit to both show and hide my sidebar, which works perfect. However, I have noticed that when I've been using timers, the animation seem to crash. For instance, I have a timer that counts down from 10 to 0, basically by decreasing the global integer by 1, every second. When I make the countdown start, and click the button to show the sidebar - it suddenly disappears. To avoid this, I have been trying to do a .makeOrigin after the animation has been done - with no luck. I have also tried to do the countdown in the timer update function running async, also with no luck.

    Any ideas on how I would approach this?

    Here is my code:

    Button for showing sidebar: self.sideview.animation.moveX(350).easeInOutSine.animate(0.5)

    Timer: self.countdownText = Foundation.Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(ViewController.counter), userInfo: nil, repeats: true)

    Counter Function:

    func counter() {
                self.count = Int(self.count - 1) //When I add this line, the animation disappears (or the sidebar)
                self.newGameLabel.text = String(self.count) //This line works, without any error.
            }
    
        }
    

    Could someone please help me to fix this? Much appreciated.

    opened by askaale 0
Owner
Draven
Go / Rails / Rust
Draven
Simple Interface Core Animation. Run type-safe animation sequencially or parallelly

Simple Interface Core Animation Sica can execute various animations sequentially or parallelly. Features Animation with duration and delay parallel /

CATS Open Source Softwares 1k Nov 10, 2022
An experiment for using SwiftUI's custom timing Animation to create an orbital-like animation.

Orbital-SwiftUI-Animation An experiment for using SwiftUI's custom timing curve to create an orbital-like animation. How it looks: How it works: Apply

Mostafa Abdellateef 7 Jan 2, 2023
SwiftUI-Text-Animation-Library - Text animation library for SwiftUI

⚠️ This repository is under construction. SwiftUI Text Animation Library Make yo

null 28 Jan 8, 2023
Swiftui-animation-observer - Track SwiftUI animation progress and completion via callbacks

SwiftUI Animation Observer Track SwiftUI animation progress and completion via c

Gordan Glavaš 9 Nov 5, 2022
(Animate CSS) animations for iOS. An easy to use library of iOS animations. As easy to use as an easy thing.

wobbly See Wobbly in action (examples) Add a drop of honey ?? to your project wobbly has a bunch of cool, fun, and easy to use iOS animations for you

Sagaya Abdulhafeez 150 Dec 23, 2021
(Animate CSS) animations for iOS. An easy to use library of iOS animations. As easy to use as an easy thing.

wobbly See Wobbly in action (examples) Add a drop of honey ?? to your project wobbly has a bunch of cool, fun, and easy to use iOS animations for you

Sagaya Abdulhafeez 150 Dec 23, 2021
Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle.

Twinkle ✨ Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle. This library creates several CAEmitterLayers and animate

patrick piemonte 600 Nov 24, 2022
LottieUI - A library developed to make Lottie easy to implement. It supports iOS and macOS

LottieUI It is a library developed to make Lottie easy to implement. It supports

jasu 51 Dec 24, 2022
Easy animation library on iOS with Swift2

Cheetah Cheetah is an animation utility on iOS with Swift. Cheetah can animate any properties since Cheetah uses simple CADisplayLink run loop to chan

Suguru Namura 592 Dec 6, 2022
Wave is a spring-based animation engine for iOS that makes it easy to create fluid, interruptible animations that feel great.

Wave is a spring-based animation engine for iOS and iPadOS. It makes it easy to create fluid, interactive, and interruptible animations that feel great.

Janum Trivedi 1.2k Jan 8, 2023
Swift animation made easy

Fluent Swift Animations made Easy Installation Add the following to your Podfile and run pod install pod 'Fluent', '~> 0.1' or add the following

Matthew Cheok 300 Jul 15, 2022
Swift easy app launcher animation.

SwiftLauncher Swift easy app launcher animation. Usage. // Twitter. let logoLayer = CALayer() logoLayer.bounds = CGRect(x: 0, y: 0, width:

iOS.Jett 1 May 25, 2022
Letters animation allows you to click on different letters and accordingly it will animate letters in a cool way. It has a very attractive UI and is very easy to use.

Letters Animation Cool Letters Animation in iOS written in Swift. Preview Table of content :- Description How to add in your project Requirement Licen

MindInventory 31 Oct 4, 2022
Numbers animation allows you to click on different numbers and accordingly it will animate numbers in a cool way. It has a very attractive UI and is very easy to use.

Numbers Animation Cool Numbers Animation in iOS written in Swift. Preview Table of content :- Description How to add in your project Requirement Licen

MindInventory 31 Oct 4, 2022
Reading animation allows you to click on the different page numbers and accordingly it will animate page changes in a cool way. It has a very attractive UI and is very easy to use.

Reading Animation Cool Reading Animation in iOS written in Swift. Preview Table of content :- Description How to add in your project Requirement Licen

MindInventory 42 Oct 4, 2022
MGFlipView allows to create flipping view in easy way without worrying about flipping animation and flipping logic.

MGFlipView About If you are looking for an easy way of implement 3D flipping view, you are in the right place. MGFlipView allows to create flipping vi

Maciej Gomółka 47 Sep 28, 2022
BWMCoverView is a very easy to use advertising the carousel view, supports circular scrolling functions such as switching, asynchronous loading of images, animation, custom is very high.

BWMCoverView BWMCoverView is a very easy to use advertising the carousel view, supports circular scrolling functions such as switching, asynchronous l

Bi Weiming 31 Mar 10, 2021
Accessbility workshop by hacking with swift. Make every app more usefull for the all the users

Accessibility Accessbility workshop by hacking with swift. Make every app more u

Pavel Surový 0 Dec 26, 2021