What is UIKit Dynamics?
• Added in iOS 7
• Adds a physics engine to UIKit
Slide 3
Slide 3 text
A physics engine? In UIKit?
Slide 4
Slide 4 text
“The UI helps users understand
and interact with the content,
but never competes with it.”
iOS Human Interface Guidelines: Designing for iOS 7
Slide 5
Slide 5 text
“Visual layers and realistic motion
impart vitality and heighten users’
delight and understanding.”
iOS Human Interface Guidelines: Designing for iOS 7
Slide 6
Slide 6 text
No content
Slide 7
Slide 7 text
How it works
• UIDynamicItem
• UIDynamicBehavior
• UIDynamicAnimator
Slide 8
Slide 8 text
UIDynamicItem
• Just a protocol
• UIView implements it
• Defines three animatable properties:
• bounds
• center
• transform
Slide 9
Slide 9 text
UIDynamicAnimator
• Responsible for applying behaviours to items
• Defines a reference view
• Manages animations
• Pauses when animations end
More on setting boundaries
• translatesReferenceBoundsIntoBoundary
• setTranslatesReferenceBoundsIntoBoundaryWithInsets:
• addBoundaryWithIdentifier:forPath:
UIPushBehavior
• Allows you to model a force
• Can be instantaneous or continuous
Slide 25
Slide 25 text
No content
Slide 26
Slide 26 text
No content
Slide 27
Slide 27 text
UIPushBehavior *behavior = [[UIPushBehavior alloc]
initWithItems:@[view1, view2]
mode:UIPushBehaviorModeInstantaneous]];
behavior.magnitude = 1.0;
behavior.angle = 0; // to the right
[animator addBehavior:behavior];
Slide 28
Slide 28 text
0.0
π
M_PI
π/2
M_PI_2
3π/2
M_PI_2 * 3
Slide 29
Slide 29 text
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
Slide 30
Slide 30 text
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 :)
Slide 31
Slide 31 text
No content
Slide 32
Slide 32 text
No content
Slide 33
Slide 33 text
No content
Slide 34
Slide 34 text
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…?
Slide 35
Slide 35 text
UIDynamicItemBehavior
• Just another UIDynamicBehavior
• Use to fine-tune your UIDynamicItems
• density
• elasticity
• friction
• etc…
Slide 36
Slide 36 text
Next steps
• UICollectionViewLayoutAttributes
• Custom dynamic behaviours
Slide 37
Slide 37 text
Gotchas
Slide 38
Slide 38 text
No content
Slide 39
Slide 39 text
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