Slides from the Easy Animation talk at Cocoaheads Copenhagen
Easy AnimationMarin Todorov
View Slide
Swift 2.0 Swift 2.0
Motivation
MotivationHow would I improve the built-in animation APIs?
Goals* easier layer animations* easier animation sequences* layer spring animations
David Rönnqvistpost on objc.io
UIView.animateWithDuration(1.0, animations: {})Create an animation contextDestroy the animation contextOriginal animations blockAnimate layer properties
CALayer() UIView()layerlayerviewdelegate
animations blockview.alpha = 0.5layer.position.y = 200layer.cornerRadius = 50UIView.actionForLayer(layer, “alpha”)CAAnimationUIView.actionForLayer(layer, “position.y”)CAAnimationUIView.actionForLayer(layer, “cornerRadius”)NSNull
layer.cornerRadius = 50CABasicAnimation(keyPath: “cornerRadius”)toValue = 50fromValue =
Layer animations
UIView.animationWithDuration(1.0, animations: { first animation }).animateWithDuration(1.0, { second animation })… etc …
Sequence animations
UIKit.animateWithDuration(…)CABasicAnimationUIKit.animateWithDuration(…springDamping: ,springInitialVelocity: …)CASpringAnimation on iOS9RBBSpringAnimation on iOS8
Feelings
Gotchas* Premature completion! * What is a damped harmonic oscillator? * Retain/release #$!
What’s next?UIView.animateWithDuration(1.0, animations: {})self.myButton.animationPath = CGPath(…)self.myButton.transform.scale.x = 1.2self.myButton.rotation = M_PI_4
How bout smth crazy?UIView.animateWithDuration(1.0, animations: {})self.myButton.center.x = 20Update the viewconstraints andthus make this workon AL? Whaaaa?
Marin TodorovThank you!www.underplot.com