simenlie / ScrubAnimator

KeyFrame animation library for iOS, supporting animation of CGRect and cornerRadius.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ScrubAnimator

MIT License

About

ScrubAnimator is a KeyFrame animation library, written in Swift, for iOS, currently supporting animation of CGRect and cornerRadius. The library makes it easy to create CGRect animations, based on duration and/or a value.

Features

  • KeyFrame: for creating animations with a lot of changes
  • Scrub: Scrub through the animation based on some value. For example a value from UISlider or UIPanGesture

Limitations

The library currently only support animation of CGRect and cornerRadius.

More Features are planned, like: borderColor, borderWidth, backgroundColor. In addition a more generic approach, where you can choose just a point, e.g. x or y pos, instead of a CGRect

Example

You can download the project to try the example. The Example code resides in ViewController.swift

Usage

let animator = Animator(duration: 5) //seconds

Add KeyFrames with a CGRect

override func viewDidLoad() {
...

//Setup the keyframes
animator.add(keyFrame: 0, frame: FRAME1)
animator.add(keyFrame: 0.3, frame: FRAME2)
animator.add(keyFrame: 1, frame: FRAME3)

...
}

Using the scrub function

let result = animator.scrubTo(keyFrame: 0.5)
self.myView.frame = result.frame

Animate based on the duration (You can also combine scrub and duration, if you scrub to a point, then call animator.animate, it will automatically pick up from where you scrubbed to)

 animator.animate(direction: .forward,
                         animations: {(result : AnimatorResult) in
                            self.myView.frame = result.frame
        })

You can also animate to the next or previous KeyFrame

 animator.step(direction: .forward, changed: {(result : AnimatorResult) in
            self.myView.frame = result.frame
        })

About

KeyFrame animation library for iOS, supporting animation of CGRect and cornerRadius.

License:MIT License


Languages

Language:Makefile 49.6%Language:Objective-C 33.1%Language:Swift 17.3%