Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Easy Animation at Cocoaheads Copenhagen

Easy Animation at Cocoaheads Copenhagen

Slides from the Easy Animation talk at Cocoaheads Copenhagen

Bbb75c4dd2e17a7e3114c730ec7144d0?s=128

Marin Todorov

October 04, 2015
Tweet

Transcript

  1. Easy Animation Marin Todorov

  2. Swift 2.0 Swift 2.0

  3. None
  4. Motivation

  5. Motivation How would I improve the built-in animation APIs?

  6. Goals * easier layer animations * easier animation sequences *

    layer spring animations
  7. David Rönnqvist post on objc.io

  8. UIView.animateWithDuration(1.0, animations: { }) Create an animation context Destroy the

    animation context Original animations block Animate layer properties
  9. CALayer() UIView() layer layer view delegate

  10. animations block view.alpha = 0.5 layer.position.y = 200 layer.cornerRadius =

    50 UIView.actionForLayer(layer, “alpha”) CAAnimation UIView.actionForLayer(layer, “position.y”) CAAnimation UIView.actionForLayer(layer, “cornerRadius”) NSNull
  11. layer.cornerRadius = 50 CABasicAnimation(keyPath: “cornerRadius”) toValue = 50 fromValue =

    <current value>
  12. Layer animations

  13. Goals * easier layer animations * easier animation sequences *

    layer spring animations
  14. UIView.animationWithDuration(1.0, animations: {
 first animation
 }).animateWithDuration(1.0, {
 second animation
 })…

    etc …
  15. Sequence animations

  16. Goals * easier layer animations * easier animation sequences *

    layer spring animations
  17. UIKit.animateWithDuration(…) CABasicAnimation UIKit.animateWithDuration(… springDamping: , springInitialVelocity: …) CASpringAnimation on iOS9

    RBBSpringAnimation on iOS8
  18. Feelings

  19. Gotchas * Premature completion!
 * What is a damped harmonic

    oscillator?
 * Retain/release #$!
  20. What’s next? UIView.animateWithDuration(1.0, animations: { }) self.myButton.animationPath = CGPath(…) self.myButton.transform.scale.x

    = 1.2 self.myButton.rotation = M_PI_4
  21. How bout smth crazy? UIView.animateWithDuration(1.0, animations: { }) self.myButton.center.x =

    20 Update the view constraints and thus make this work on AL? Whaaaa?
  22. Marin Todorov Thank you! www.underplot.com