SlideShare a Scribd company logo
UIKit Dynamics
Craig VanderZwaag

craig@bluehulastudios.com
Tuesday, October 15, 13

@bHCraigV
ADD DEPTH
AND GRAVITY
AND WEIGHT
AND DELIGHT!

Tuesday, October 15, 13
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
DEMO
Tuesday, October 15, 13
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
CONCEPTS
• Dynamic

Items

• Dynamic

Behaviors

• Dynamic Animators

Tuesday, October 15, 13
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
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
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
CODE
 TIME

Tuesday, October 15, 13
STEP ONE:
CREATE A DYNAMIC ITEM
@protocol UIDynamicItem NSObject
@property (nonatomic, readwrite) CGPoint center;
@property (nonatomic, readonly) CGRect bounds;
@property (nonatomic, readwrite) CGAffineTransform transform;
@end

NS_CLASS_AVAILABLE_IOS(2_0) @interface UIView :
UIResponderNSCoding, UIAppearance, UIAppearanceContainer,
UIDynamicItem {

Tuesday, October 15, 13
STEP ONE:
CREATE A DYNAMIC ITEM
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect frame = {CGPointZero, {100.0, 100.0}};
self.button = [[UIButton alloc] initWithFrame:frame];
self.button.backgroundColor = [UIColor purpleColor];
[self.view addSubview:self.button];
...
}

Tuesday, October 15, 13
STEP TWO:
CREATE A DYNAMIC ANIMATOR
NS_CLASS_AVAILABLE_IOS(7_0) @interface UIDynamicAnimator: NSObject
- (instancetype)initWithReferenceView:(UIView*)view;
- (void)addBehavior:(UIDynamicBehavior *)behavior;
- (void)removeBehavior:(UIDynamicBehavior *)behavior;
- (void)removeAllBehaviors;
@property (nonatomic, readonly) UIView* referenceView;
@property (nonatomic, readonly, copy) NSArray* behaviors;

Tuesday, October 15, 13
STEP TWO:
CREATE A DYNAMIC ANIMATOR
@implementation ViewController
- (void)viewDidLoad
{
...
self.animator = [[UIDynamicAnimator alloc]
initWithReferenceView:self.view];
...
}

Tuesday, October 15, 13
STEP THREE:
ADD BEHAVIORS
NS_CLASS_AVAILABLE_IOS(7_0) @interface UIDynamicBehavior : NSObject
- (void)addChildBehavior:(UIDynamicBehavior *)behavior;
- (void)removeChildBehavior:(UIDynamicBehavior *)behavior;
@property (nonatomic, readonly, copy) NSArray* childBehaviors;
// When running, the dynamic animator calls the action block on
every animation step.
@property (nonatomic,copy) void (^action)(void);
- (void)willMoveToAnimator:(UIDynamicAnimator *)dynamicAnimator; //
nil when being removed from an animator
@property (nonatomic, readonly) UIDynamicAnimator *dynamicAnimator;
@end

Tuesday, October 15, 13
STEP THREE:
ADD BEHAVIORS- GRAVITY
NS_CLASS_AVAILABLE_IOS(7_0) @interface UIGravityBehavior :
UIDynamicBehavior
- (instancetype)initWithItems:(NSArray *)items;
- (void)addItem:(id UIDynamicItem)item;
- (void)removeItem:(id UIDynamicItem)item;
@property (nonatomic, readonly, copy) NSArray* items;
// The default value for the gravity vector is (0.0, 1.0)
// The acceleration for a dynamic item subject to a (0.0, 1.0) gravity vector is
downwards at 1000 points per second².

@property (readwrite, nonatomic) CGVector gravityDirection;

@property (readwrite, nonatomic) CGFloat angle;
@property (readwrite, nonatomic) CGFloat magnitude;
- (void)setAngle:(CGFloat)angle magnitude:(CGFloat)magnitude;
@end

Tuesday, October 15, 13
STEP THREE:
ADD BEHAVIORS- GRAVITY
- (void)viewDidLoad
{
[super viewDidLoad];
...
UIGravityBehavior* gravityBehavior = [[UIGravityBehavior alloc]
initWithItems:@[self.button]];
[self.animator addBehavior:gravityBehavior];
...
}

Tuesday, October 15, 13
TO
 XCODE
 WE
 GO
https://bitbucket.org/craigvz/dynamicssampler

Tuesday, October 15, 13
Tuesday, October 15, 13
WHAT HAPPENED?

Tuesday, October 15, 13
•We

fell through the floor

•Button

needs to collide with the edge of
our view to stay on the screen

Tuesday, October 15, 13
STEP FOUR:
ADD BEHAVIORS- COLLISION
NS_CLASS_AVAILABLE_IOS(7_0) @interface UICollisionBehavior :
UIDynamicBehavior
- (instancetype)initWithItems:(NSArray *)items;
- (void)addItem:(id UIDynamicItem)item;
- (void)removeItem:(id UIDynamicItem)item;
@property (nonatomic, readonly, copy) NSArray* items;
@property (nonatomic, readwrite) UICollisionBehaviorMode collisionMode;
@property (nonatomic, readwrite) BOOL
translatesReferenceBoundsIntoBoundary;
- (void)setTranslatesReferenceBoundsIntoBoundaryWithInsets:
(UIEdgeInsets)insets;
...
@end

Tuesday, October 15, 13
STEP FOUR:
ADD BEHAVIORS- COLLISION
- (void)viewDidLoad
{
[super viewDidLoad];
...
UICollisionBehavior* collisionBehavior = [[UICollisionBehavior
alloc] initWithItems:@[self.button]];
collisionBehavior.collisionMode =
UICollisionBehaviorModeBoundaries;
collisionBehavior.translatesReferenceBoundsIntoBoundary = YES;
[self.animator addBehavior:collisionBehavior];
...
}

Tuesday, October 15, 13
STEP FIVE:
ADD BEHAVIORS- PUSH
NS_CLASS_AVAILABLE_IOS(7_0) @interface UIPushBehavior : UIDynamicBehavior
- (instancetype)initWithItems:(NSArray *)items mode:(UIPushBehaviorMode)mode;
- (void)addItem:(id UIDynamicItem)item;
- (void)removeItem:(id UIDynamicItem)item;
@property (nonatomic, readonly, copy) NSArray* items;
- (UIOffset)targetOffsetFromCenterForItem:(id UIDynamicItem)item;
- (void)setTargetOffsetFromCenter:(UIOffset)o forItem:(id UIDynamicItem)item;
@property (nonatomic, readonly) UIPushBehaviorMode mode;
@property (nonatomic, readwrite) BOOL active;
@property (readwrite, nonatomic) CGFloat angle;
// A continuous force vector with a magnitude of 1.0, applied to a 100 point x 100 point
view whose density value is 1.0, results in view acceleration of 100 points per s^2
@property (readwrite, nonatomic) CGFloat magnitude;
@property (readwrite, nonatomic) CGVector pushDirection;
- (void)setAngle:(CGFloat)angle magnitude:(CGFloat)magnitude;
@end

Tuesday, October 15, 13
STEP FIVE:
ADD BEHAVIORS- PUSH
- (void)viewDidLoad
{
...
self.pushBehavior = [[UIPushBehavior alloc]
initWithItems:@[self.button]
mode:UIPushBehaviorModeInstantaneous];
CGFloat magnitude = 20.0;
[self.pushBehavior setAngle:-M_PI_2 magnitude:magnitude];
self.pushBehavior.active = NO;
[self.animator addBehavior:self.pushBehavior];
}

...

Tuesday, October 15, 13
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
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
STEP SIX:
TWEAK ITEM PROPERTIES
- (void)viewDidLoad
{
[super viewDidLoad];
...
UIDynamicItemBehavior* dynamicItemBehavior =
[[UIDynamicItemBehavior alloc] initWithItems:@[self.button]];
dynamicItemBehavior.elasticity = 0.5;
dynamicItemBehavior.resistance = 1.0;
...
}

Tuesday, October 15, 13
UNITS

Tuesday, October 15, 13
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
Ad

More Related Content

Recently uploaded (20)

Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 

Featured (20)

2024 Trend Updates: What Really Works In SEO & Content Marketing
2024 Trend Updates: What Really Works In SEO & Content Marketing2024 Trend Updates: What Really Works In SEO & Content Marketing
2024 Trend Updates: What Really Works In SEO & Content Marketing
Search Engine Journal
 
Storytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design ProcessStorytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design Process
Chiara Aliotta
 
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
OECD Directorate for Financial and Enterprise Affairs
 
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
 
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
2024 Trend Updates: What Really Works In SEO & Content Marketing
2024 Trend Updates: What Really Works In SEO & Content Marketing2024 Trend Updates: What Really Works In SEO & Content Marketing
2024 Trend Updates: What Really Works In SEO & Content Marketing
Search Engine Journal
 
Storytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design ProcessStorytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design Process
Chiara Aliotta
 
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
 
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
Ad

UIKit Dynamics

  • 2. ADD DEPTH AND GRAVITY AND WEIGHT AND DELIGHT! Tuesday, October 15, 13
  • 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
  • 6. CONCEPTS • Dynamic Items • Dynamic Behaviors • Dynamic Animators Tuesday, October 15, 13
  • 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
  • 10. CODE
  • 12. STEP ONE: CREATE A DYNAMIC ITEM @protocol UIDynamicItem NSObject @property (nonatomic, readwrite) CGPoint center; @property (nonatomic, readonly) CGRect bounds; @property (nonatomic, readwrite) CGAffineTransform transform; @end NS_CLASS_AVAILABLE_IOS(2_0) @interface UIView : UIResponderNSCoding, UIAppearance, UIAppearanceContainer, UIDynamicItem { Tuesday, October 15, 13
  • 13. STEP ONE: CREATE A DYNAMIC ITEM - (void)viewDidLoad { [super viewDidLoad]; CGRect frame = {CGPointZero, {100.0, 100.0}}; self.button = [[UIButton alloc] initWithFrame:frame]; self.button.backgroundColor = [UIColor purpleColor]; [self.view addSubview:self.button]; ... } Tuesday, October 15, 13
  • 14. STEP TWO: CREATE A DYNAMIC ANIMATOR NS_CLASS_AVAILABLE_IOS(7_0) @interface UIDynamicAnimator: NSObject - (instancetype)initWithReferenceView:(UIView*)view; - (void)addBehavior:(UIDynamicBehavior *)behavior; - (void)removeBehavior:(UIDynamicBehavior *)behavior; - (void)removeAllBehaviors; @property (nonatomic, readonly) UIView* referenceView; @property (nonatomic, readonly, copy) NSArray* behaviors; Tuesday, October 15, 13
  • 15. STEP TWO: CREATE A DYNAMIC ANIMATOR @implementation ViewController - (void)viewDidLoad { ... self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view]; ... } Tuesday, October 15, 13
  • 16. STEP THREE: ADD BEHAVIORS NS_CLASS_AVAILABLE_IOS(7_0) @interface UIDynamicBehavior : NSObject - (void)addChildBehavior:(UIDynamicBehavior *)behavior; - (void)removeChildBehavior:(UIDynamicBehavior *)behavior; @property (nonatomic, readonly, copy) NSArray* childBehaviors; // When running, the dynamic animator calls the action block on every animation step. @property (nonatomic,copy) void (^action)(void); - (void)willMoveToAnimator:(UIDynamicAnimator *)dynamicAnimator; // nil when being removed from an animator @property (nonatomic, readonly) UIDynamicAnimator *dynamicAnimator; @end Tuesday, October 15, 13
  • 17. STEP THREE: ADD BEHAVIORS- GRAVITY NS_CLASS_AVAILABLE_IOS(7_0) @interface UIGravityBehavior : UIDynamicBehavior - (instancetype)initWithItems:(NSArray *)items; - (void)addItem:(id UIDynamicItem)item; - (void)removeItem:(id UIDynamicItem)item; @property (nonatomic, readonly, copy) NSArray* items; // The default value for the gravity vector is (0.0, 1.0) // The acceleration for a dynamic item subject to a (0.0, 1.0) gravity vector is downwards at 1000 points per second². @property (readwrite, nonatomic) CGVector gravityDirection; @property (readwrite, nonatomic) CGFloat angle; @property (readwrite, nonatomic) CGFloat magnitude; - (void)setAngle:(CGFloat)angle magnitude:(CGFloat)magnitude; @end Tuesday, October 15, 13
  • 18. STEP THREE: ADD BEHAVIORS- GRAVITY - (void)viewDidLoad { [super viewDidLoad]; ... UIGravityBehavior* gravityBehavior = [[UIGravityBehavior alloc] initWithItems:@[self.button]]; [self.animator addBehavior:gravityBehavior]; ... } Tuesday, October 15, 13
  • 19. TO
  • 21.  WE
  • 25. •We fell through the floor •Button needs to collide with the edge of our view to stay on the screen Tuesday, October 15, 13
  • 26. STEP FOUR: ADD BEHAVIORS- COLLISION NS_CLASS_AVAILABLE_IOS(7_0) @interface UICollisionBehavior : UIDynamicBehavior - (instancetype)initWithItems:(NSArray *)items; - (void)addItem:(id UIDynamicItem)item; - (void)removeItem:(id UIDynamicItem)item; @property (nonatomic, readonly, copy) NSArray* items; @property (nonatomic, readwrite) UICollisionBehaviorMode collisionMode; @property (nonatomic, readwrite) BOOL translatesReferenceBoundsIntoBoundary; - (void)setTranslatesReferenceBoundsIntoBoundaryWithInsets: (UIEdgeInsets)insets; ... @end Tuesday, October 15, 13
  • 27. STEP FOUR: ADD BEHAVIORS- COLLISION - (void)viewDidLoad { [super viewDidLoad]; ... UICollisionBehavior* collisionBehavior = [[UICollisionBehavior alloc] initWithItems:@[self.button]]; collisionBehavior.collisionMode = UICollisionBehaviorModeBoundaries; collisionBehavior.translatesReferenceBoundsIntoBoundary = YES; [self.animator addBehavior:collisionBehavior]; ... } Tuesday, October 15, 13
  • 28. STEP FIVE: ADD BEHAVIORS- PUSH NS_CLASS_AVAILABLE_IOS(7_0) @interface UIPushBehavior : UIDynamicBehavior - (instancetype)initWithItems:(NSArray *)items mode:(UIPushBehaviorMode)mode; - (void)addItem:(id UIDynamicItem)item; - (void)removeItem:(id UIDynamicItem)item; @property (nonatomic, readonly, copy) NSArray* items; - (UIOffset)targetOffsetFromCenterForItem:(id UIDynamicItem)item; - (void)setTargetOffsetFromCenter:(UIOffset)o forItem:(id UIDynamicItem)item; @property (nonatomic, readonly) UIPushBehaviorMode mode; @property (nonatomic, readwrite) BOOL active; @property (readwrite, nonatomic) CGFloat angle; // A continuous force vector with a magnitude of 1.0, applied to a 100 point x 100 point view whose density value is 1.0, results in view acceleration of 100 points per s^2 @property (readwrite, nonatomic) CGFloat magnitude; @property (readwrite, nonatomic) CGVector pushDirection; - (void)setAngle:(CGFloat)angle magnitude:(CGFloat)magnitude; @end Tuesday, October 15, 13
  • 29. STEP FIVE: ADD BEHAVIORS- PUSH - (void)viewDidLoad { ... self.pushBehavior = [[UIPushBehavior alloc] initWithItems:@[self.button] mode:UIPushBehaviorModeInstantaneous]; CGFloat magnitude = 20.0; [self.pushBehavior setAngle:-M_PI_2 magnitude:magnitude]; self.pushBehavior.active = NO; [self.animator addBehavior:self.pushBehavior]; } ... 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
  • 32. STEP SIX: TWEAK ITEM PROPERTIES - (void)viewDidLoad { [super viewDidLoad]; ... UIDynamicItemBehavior* dynamicItemBehavior = [[UIDynamicItemBehavior alloc] initWithItems:@[self.button]]; dynamicItemBehavior.elasticity = 0.5; dynamicItemBehavior.resistance = 1.0; ... } 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
  • 35. DELEGATES @protocol UIDynamicAnimatorDelegate NSObject @optional - (void)dynamicAnimatorWillResume:(UIDynamicAnimator*)animator; - (void)dynamicAnimatorDidPause:(UIDynamicAnimator*)animator; @end 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
  • 38. THE