3. UIKIT DYNAMICS
• New
in iOS7 SDK
• Brings
real-world physics and interaction
behaviors to your apps
• 2-Dimensional
interaction
Tuesday, October 15, 13
animations and
5. HOW?
• Integrated
physics engine and animator
• PhysicsKit-
Shared with the new Sprite
Kit framework
• Based
Tuesday, October 15, 13
on Box 2D http://box2d.org
7. DYNAMIC ITEMS
• Objects
that can be animated
• Minimal
set of geometry properties
• Don’t
necessarily have to be views or
even on screen
Tuesday, October 15, 13
8. DYNAMIC BEHAVIORS
• Encapsulate
• Associated
a set of “physical” attributes and behaviors
to dynamic items to impart them with
behaviors
• Gravity, Collision, Friction
• Resistance, Velocity, Attachment
• Can
Be composed in a hierarchy
Tuesday, October 15, 13
9. DYNAMIC ANIMATOR
• Coordinates
a view
the dynamic items and behaviors in
• Updates
the “scene” with each step of the
animation
• Holds
all the behaviors that describe how
dynamic items react
Tuesday, October 15, 13
30. STEP SIX:
TWEAK ITEM PROPERTIES
NS_CLASS_AVAILABLE_IOS(7_0) @interface UIDynamicItemBehavior : UIDynamicBehavior
...
@property (readwrite, nonatomic) CGFloat elasticity; // Usually between 0
(inelastic) and 1 (collide elastically)
@property (readwrite, nonatomic) CGFloat friction; // 0 being no friction between
objects slide along each other
@property (readwrite, nonatomic) CGFloat density; // 1 by default
@property (readwrite, nonatomic) CGFloat resistance; // 0: no velocity damping
@property (readwrite, nonatomic) CGFloat angularResistance; // 0: no angular
velocity damping
@property (readwrite, nonatomic) BOOL allowsRotation; // force an item to never
rotate
...
@end
Tuesday, October 15, 13
31. STEP SIX:
TWEAK ITEM PROPERTIES
NS_CLASS_AVAILABLE_IOS(7_0) @interface UIDynamicItemBehavior : UIDynamicBehavior
...
// The linear velocity, expressed in points per second, that you want to add to
the specified dynamic item
// If called before being associated to an animator, the behavior will accumulate
values until being associated to an animator
- (void)addLinearVelocity:(CGPoint)velocity forItem:(id UIDynamicItem)item;
- (CGPoint)linearVelocityForItem:(id UIDynamicItem)item;
// The angular velocity, expressed in radians per second, that you want to add to
the specified dynamic item
// If called before being associated to an animator, the behavior will accumulate
values until being associated to an animator
- (void)addAngularVelocity:(CGFloat)velocity forItem:(id UIDynamicItem)item;
- (CGFloat)angularVelocityForItem:(id UIDynamicItem)item;
@end
Tuesday, October 15, 13
34. UNITS
• Many
properties have their own unit of measure
• UIGravityBehavior’s
• 1.0
= 1000 points / second2
• UIPushBehavior
• 1.0
magnitude:
magnitude:
= 100 points / second2 for 100 point x 100 point item
with density = 1.0 (UIKit Newton)
Tuesday, October 15, 13
36. DELEGATES
@protocol UICollisionBehaviorDelegate NSObject
@optional
- (void)collisionBehavior:(UICollisionBehavior*)behavior beganContactForItem:
(id UIDynamicItem)item1 withItem:(id UIDynamicItem)item2 atPoint:
(CGPoint)p;
- (void)collisionBehavior:(UICollisionBehavior*)behavior endedContactForItem:
(id UIDynamicItem)item1 withItem:(id UIDynamicItem)item2;
// The identifier of a boundary created with
translatesReferenceBoundsIntoBoundary or
setTranslatesReferenceBoundsIntoBoundaryWithInsets is nil
- (void)collisionBehavior:(UICollisionBehavior*)behavior beganContactForItem:
(id UIDynamicItem)item withBoundaryIdentifier:(id NSCopying)identifier
atPoint:(CGPoint)p;
- (void)collisionBehavior:(UICollisionBehavior*)behavior endedContactForItem:
(id UIDynamicItem)item withBoundaryIdentifier:(id NSCopying)identifier;
@end
Tuesday, October 15, 13