Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

anim lib ios

Eonist edited this page Jul 24, 2017 · 22 revisions

Notes on anim lib for ios: πŸ“

  • based on AnimLib for macOS
/**
 * Idea for Animator closure (curried closure?)
 * NOTE: This syntax creates a rect and animates it in just 2 lines of code 😍😍😍
 * Interruptible/Interactive 60FPS animation
 */
let rect = addSubView(CGRect(50,50).fill(.blue).draw())//adds a green rect to view via GraphicsLib 2.0 πŸ‘Œ
Animator(from:0,to:100,duration:0.5,easing:.easeOut){ val in 
	let color:NSColor = .blue.interpolate(.red,val/100)
	rect.fill = Fill(color)
	rect.draw()//draws a new color
	rect.x = val//moves the view
}.start()/*call start directly or assign to a variable for later execution*/
  • You also have LoopAnimator, Mover, Friction, Elastic etc. (Elastic is a RubberBand like spring solver)

  • You also have all the easing equations from Robert Penner. .easeOut, sineEaseOut, bounceBack etc etc.

  • .onComplete .onFrame .onStop .onStart Are all callBack methods you can assign locally scoped handlers to.

  • Unlike Animator for mac we should not use EventSender for Animator for iOS as people may want to use Animator but not EventSender (you can always ad-hock EventSender through extensions etc)

  • Animator should be a struct.

  • Easing should be a protocol and the Robert Penner equations should simply be static functions in an extension extending Easing. So you can use the dot syntax: .easeOut (could even be enum)

  • AnimLib for iOS should be a standalone project w/ no syntactic sugar as its pretty simple to setup.

Chaining: β›“

Animator(/*...*/){ val in
	/*animate stuff here*/
}.onComplete{
	/*anim completed*/	
}.animate(/*...*/){
	/*animate stuff here*/
}.onFrame{ curFrame in
	/*Frame animation here*/
}.onComplete{
	/*Anim chain complete*/
}

/*And the entire anim chain is Interruptible, you can manipulate .y while the chain manipulates .x for instance even .x for that matter πŸ‘Œ*/
//And the same chaining for bg/main thread tasks: 
SomeSerialQueue().bg { () -> () in
  println("Background 1, thread = \(NSThread.currentThread())")
}.main { () -> () in
  println("Main 1, thread = \(NSThread.currentThread())")
}.bg { () -> () in
  println("Background 2, thread = \(NSThread.currentThread())")
}.main { () -> () in
  println("Main 2, thread = \(NSThread.currentThread())")
}.start()

Animation patters

This may be added ad-hock. fade in/out, zoom in/out, flip, pop, shake, rotate, move etc.

And maybe something like the bellow

view.animate(.squeezeFade(way: .in, direction: .down))
.then(.pop(repeatCount: 1))
.then(.shake(repeatCount: 1))
.then(.squeeze(way: .in, direction: .down))
.then(.wobble(repeatCount: 1))
.then(.flip(along: .x))
.then(.flip(along: .y))
.then(.slideFade(way: .out, direction: .down))

Follow path would be trivial to implement. 🐝

  • Support for CubicBezier and PolyLine. Via CGPath. Even adjusting angle would be trivial. Just find a tangent at P for CubicBezier.

  • Use your P for T equation to find P on Path.

  • You would need a lenOfCubicBezier equation. (for even speed)

  • Then use your pathDivide equation. πŸ‘Œ

Animation manifest

  • A mixture of .svg and animation .xml see legacy documentation for this.

  • Bridge AE anim doc to AnimLib manifest doc. (Future improvement)

  • Animator is an attempt to strike a balance between 4 pillars: Ease-of use, Customizability, Features and Performance.