$30 off During Our Annual Pro Sale. View Details »

Easy Animation at Cocoaheads Copenhagen

Easy Animation at Cocoaheads Copenhagen

Slides from the Easy Animation talk at Cocoaheads Copenhagen

Marin Todorov

October 04, 2015
Tweet

More Decks by Marin Todorov

Other Decks in Technology

Transcript

  1. Easy Animation
    Marin Todorov

    View Slide

  2. Swift 2.0 Swift 2.0

    View Slide

  3. View Slide

  4. Motivation

    View Slide

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

    View Slide

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

    View Slide

  7. David Rönnqvist
    post on objc.io

    View Slide

  8. UIView.animateWithDuration(1.0, animations: {
    })
    Create an animation context
    Destroy the animation context
    Original animations block
    Animate layer properties

    View Slide

  9. CALayer() UIView()
    layer
    layer
    view
    delegate

    View Slide

  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

    View Slide

  11. layer.cornerRadius = 50
    CABasicAnimation(keyPath: “cornerRadius”)
    toValue = 50
    fromValue =

    View Slide

  12. Layer animations

    View Slide

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

    View Slide

  14. UIView.animationWithDuration(1.0, animations: {

    first animation

    }).animateWithDuration(1.0, {

    second animation

    })… etc …

    View Slide

  15. Sequence animations

    View Slide

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

    View Slide

  17. UIKit.animateWithDuration(…)
    CABasicAnimation
    UIKit.animateWithDuration(…
    springDamping: ,
    springInitialVelocity: …)
    CASpringAnimation on iOS9
    RBBSpringAnimation on iOS8

    View Slide

  18. Feelings

    View Slide

  19. Gotchas
    * Premature completion!

    * What is a damped harmonic oscillator?

    * Retain/release #$!

    View Slide

  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

    View Slide

  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?

    View Slide

  22. Marin Todorov
    Thank you!
    www.underplot.com

    View Slide