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

Introduction to UIKit Dynamics

Introduction to UIKit Dynamics

First given at Alt Tech Talks London 2013

Simon Whitaker

December 16, 2013
Tweet

More Decks by Simon Whitaker

Other Decks in Technology

Transcript

  1. What is UIKit Dynamics? • Added in iOS 7 •

    Adds a physics engine to UIKit
  2. “The UI helps users understand and interact with the content,

    but never competes with it.” iOS Human Interface Guidelines: Designing for iOS 7
  3. “Visual layers and realistic motion impart vitality and heighten users’

    delight and understanding.” iOS Human Interface Guidelines: Designing for iOS 7
  4. UIDynamicItem • Just a protocol • UIView implements it •

    Defines three animatable properties: • bounds • center • transform
  5. UIDynamicAnimator • Responsible for applying behaviours to items • Defines

    a reference view • Manages animations • Pauses when animations end
  6. UIDynamicBehavior • Models a real-world physical behaviour • UIKit provides

    a number of built-in behaviours • You can create your own
  7. UIGravityBehavior • Models gravity • Add to an item and

    it falls downwards • You can optionally configure magnitude and angle
  8. Units • Earth gravity: 9.8 m/s² • UIKit gravity: 1000

    pt/s² • Adjust with magnitude property
  9. UICollisionBehavior • Allows you to specify the way dynamic items

    react to the things around them • Collide with other dynamic items and/or boundaries
  10. Units • 1 Newton: force required to give a 1kg

    mass an acceleration of 1 m/s² • 1 UIKit Newton: force required to give a 100 x 100 pt dynamic item with a density of 1.0 an acceleration of 100 pt/s² • magnitude property is measured in UIKit Newtons
  11. Getting the right magnitude • Calculate mass of view based

    on size and density, use calculus to determine force needed for net overall movement • Or: fiddle with magnitude until it looks right :)
  12. Wait, you said density? • “1 UIKit Newton: force required

    to give a 100 x 100 pt dynamic item with a density of 1.0 an acceleration of 100 pt/s²” • But UIDynamicItem only defines bounds, center, transform • So…?
  13. UIDynamicItemBehavior • Just another UIDynamicBehavior • Use to fine-tune your

    UIDynamicItems • density • elasticity • friction • etc…
  14. UI Kit Dynamics Summary • New in iOS 7 •

    Give UIViews real-world physical behaviours with very little code • Create animator, associate with a reference view • Create behaviours, associate with dynamic items • Add the behaviours to the animator