SlideShare a Scribd company logo
1 of 33
Download to read offline
Core	
  Anima+on	
  

  Jussi	
  Pohjolainen	
  
UIVIEW	
  ANIMATION	
  
UIView	
  Anima+ons	
  
•  Several	
  view	
  proper+es	
  can	
  be	
  animated	
  
       –  Anima+on:	
  change	
  property	
  over	
  +me	
  
•  UIView	
  does	
  most	
  of	
  the	
  job	
  
•  Two	
  ways	
  
       –  Block-­‐based	
  anima:ons	
  (recommended)	
  
       –  Begin/commit	
  anima+ons	
  
	
  
Animatable	
  Proper+es	
  
•    frame	
  
•    bounds	
  
•    center	
  
•    transform	
  
     –  Rota+on,	
  Scale,	
  Move..	
  
•  alpha	
  
•  backgroundColor	
  
•  contentStretch	
  
UIView	
  Block	
  Methods	
  for	
  Anima+on	
  
Animate	
  changes	
  to	
  one	
  or	
  more	
  views	
  using	
  the	
  specified	
  dura5on,	
  delay,	
  op5ons,	
  and	
  
comple5on	
  handler.
+ animateWithDuration:delay:options:animations:completion:

Animate	
  changes	
  to	
  one	
  or	
  more	
  views	
  using	
  the	
  specified	
  dura5on	
  and	
  comple5on	
  handler.	
  
+ animateWithDuration:animations:completion:

Animate	
  changes	
  to	
  one	
  or	
  more	
  views	
  using	
  the	
  specified	
  dura5on.
+ animateWithDuration:animations:

Creates	
  a	
  transi5on	
  anima5on	
  for	
  the	
  specified	
  container	
  view.
+ transitionWithView:duration:options:animations:completion:

Creates	
  a	
  transi5on	
  anima5on	
  between	
  the	
  specified	
  views	
  using	
  the	
  given	
  parameters.
+ transitionFromView:toView:duration:options:completion:
Op+ons	
  
•  Lot	
  of	
  anima+on	
  op+ons	
  
    –  CurveEaseIn,	
  out,	
  linear	
  
    –  Repeat..	
  
•  Can	
  be	
  combined	
  using	
  |	
  
    –  UIViewAnimationOptionCurveEaseIn |
       UIViewAnimationOptionAutoreverse
Anima+on	
  with	
  Blocks	
  
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    [UIView animateWithDuration:5.0

            animations:^{
                [animatingView setAlpha:0];
                [animatingView setCenter:CGPointMake(animatingView.center.x+50.0,
                                                     animatingView.center.y+50.0)];
                }

            completion:^(BOOL finished) {
                [animatingView removeFromSuperview];
            }

    ];
}
CORE	
  ANIMATION	
  
Core	
  Anima+on	
  Layer	
  	
  
•  Anima+on	
  is	
  an	
  important	
  part	
  of	
  iOS	
  	
  
•  Add	
  QuartzCore	
  framework	
  to	
  your	
  project	
  
•  Use	
  classes	
  	
  
       –  CALayer	
  
           •  When	
  drawing	
  using	
  layers,	
  drawing	
  is	
  hardware-­‐
              accelerated	
  
           •  Layer	
  is	
  a	
  buffer	
  containing	
  a	
  bitmap	
  
       –  CAAnima+on	
  
	
  
Implicit	
  Layer	
  
•  Every	
  UIView	
  has	
  an	
  CALayer	
  
    –  When	
  UIView	
  draws	
  itself,	
  the	
  view	
  image	
  is	
  in	
  
       CALayer	
  
•  View	
  creates	
  a	
  layer:	
  implicit	
  layer	
  
    –  Matching	
  view	
  hierarchy	
  and	
  layer	
  hierarchy	
  
Explicit	
  Layer	
  
•  To	
  create	
  a	
  explicit	
  layer,	
  just	
  create	
  instance	
  
   of	
  CALayer	
  
•  Layer	
  has	
  bounds	
  and	
  posi+on	
  
•  Posi+on	
  is	
  by	
  default	
  the	
  center	
  of	
  the	
  layer.	
  
   Uses	
  coordinates	
  of	
  the	
  superlayer’s	
  
   coordinate	
  system	
  
Explicit	
  Layer	
  
CALayer* layer = [[CALayer alloc] init];

// Setting bounds to layer
CGRect bounds = CGRectMake(0.0, 0.0, 100.0, 100.0);
[layer setBounds:bounds];

// Setting *center* position to layer (uses superlayer's coordinate system)
CGPoint position = CGPointMake(50.0, 150.0);
[layer setPosition:position];

// Setting color to layer
UIColor* red = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.5];
// Cast from UIKit to Core Graphics
CGColorRef redRef = [red CGColor];
[layer setBackgroundColor:redRef];

[[[self view] layer] addSublayer: layer];
UIColor,	
  CGColorRef	
  
               UIImage,	
  CGImageRef?	
  
•  QuartzCore	
  frame	
  and	
  Core	
  Graphics	
  
   framework	
  eist	
  on	
  both	
  iOS	
  and	
  Mac	
  OS	
  X	
  
•  UIKit	
  exists	
  only	
  on	
  iOS	
  
    –  UIImage,	
  UIColor	
  …	
  
•  Due	
  to	
  portability	
  QuartzCore	
  uses	
  classes	
  like	
  
    –  CGImageRef,	
  CGColorRef	
  
•  UIKit	
  provides	
  methods	
  to	
  access	
  Core	
  
   Craphics	
  counterparts	
  
Using	
  Image	
  
// Create a UIImage
UIImage* layerImage = [UIImage imageNamed:@"dude.png"];

// Get underlying CGImage
CGImageRef image = [layerImage CGImage];

// CGImageRef => typecast struct CGImage*
// To cast from C-pointer to Objective-C id, we use
// __bridge
[layer setContents: (__bridge id)(image)];

// Fill the layer and maintain the aspect ratio
[layer setContentsGravity:kCAGravityResizeAspect];

[[[self view] layer] addSublayer: layer];
ZPosi+on	
  
•  Layers	
  exist	
  in	
  hierarchy	
  
    –  Can	
  have	
  sublayers	
  
    –  Each	
  layer	
  has	
  pointer	
  back	
  to	
  its	
  parent:	
  
       superlayer	
  
•  Layer	
  draws	
  on	
  top	
  of	
  its	
  superlayer	
  
•  What	
  about	
  siblings	
  and	
  overlapping?	
  
    –  Layer	
  has	
  property	
  zPosi+on	
  
    –  If	
  siblings	
  overlap,	
  layer	
  with	
  higher	
  zPosi+on	
  is	
  
       composed	
  on	
  top.	
  
Example	
  
// Layer 2 will be on top of layer1
[layer1 setZPosition:0.0];
[layer2 setZPosition:1.0];

// Set background color to layer2
UIColor* red = [UIColor colorWithRed:1.0 green:0.0 blue:0.0
alpha:0.5];
CGColorRef redRef = [red CGColor];
[layer2 setBackgroundColor:redRef];

// add layers as siblings
[[[self view] layer] addSublayer: layer1];
[[[self view] layer] addSublayer: layer2];
Implicitly	
  Animatable	
  Proper+es	
  
•  Several	
  CALayer	
  proper+es	
  are	
  implicitly	
  
   animatable	
  
   –  When	
  a	
  se?er	
  is	
  called,	
  proper5es	
  are	
  animated!	
  
   –  Calling	
  setPosi+on	
  will	
  animate	
  layer	
  from	
  a	
  to	
  b	
  
•  The	
  animatable	
  property	
  changes	
  to	
  its	
  
     des+na+on	
  value	
  over	
  constant	
  +me	
  interval	
  
•  Changing	
  property	
  while	
  being	
  animated	
  
     starts	
  another	
  anima+on:	
  anima+on	
  seems	
  
     slow	
  
	
  
Disable	
  implicit	
  anima+on	
  
•  To	
  disable	
  implicit	
  anima+on,	
  use	
  anima+on	
  
   transac+on	
  
•  Batch	
  anima+ons	
  and	
  set	
  there	
  parameters,	
  
   like	
  dura+on	
  and	
  anima+on	
  curve	
  
•  Set	
  begin	
  and	
  commit	
  to	
  CATransac+on	
  
CAANIMATION	
  
About	
  Anima+on	
  
•  Anima+on	
  object	
  changes	
  over	
  :me	
  
•  Instruc+on	
  set	
  that	
  can	
  be	
  added	
  to	
  a	
  CALayer	
  
   instance	
  
•  When	
  instruc+ons	
  are	
  added	
  to	
  layer,	
  layer	
  
   begins	
  following	
  the	
  instruc+ons	
  of	
  the	
  
   anima+on.	
  
•  Many	
  proper+es	
  can	
  be	
  animated:	
  opacity,	
  
   posi+on,	
  transform,	
  bounds	
  …	
  
Anima+on	
  Classes	
  
•  CAAnima+on	
  (Abstract)	
  
   –  CAPropertyAnima+on	
  (Abstract)	
  
      •  CABasicAnima:on	
  
      •  CAKeyFrameAnima:on	
  
   –  CAAnima:onGroup	
  
   –  CATransi:on	
  
CABasicAnima+on	
  
•  CABasicAnima+on	
  has	
  two	
  values	
  
   –  fromValue
   –  toValue
   –  (and	
  the	
  dura+on	
  from	
  CAAnimation)	
  
•  Decide	
  the	
  property,	
  then	
  set	
  values	
  
   fromValue	
  to	
  toValue	
  and	
  set	
  dura+on	
  also	
  
Spinning	
  Layer	
  Example	
  
// Create CABasicAnimation and inform about the property
// we are going to influence
CABasicAnimation *spin = [CABasicAnimation
animationWithKeyPath:@"transform.rotation"];

// Changes rotation (uses radians)
[spin setToValue:[NSNumber numberWithFloat:M_PI*2.0]];

// Set duration to one second
[spin setDuration:1.0];

// Repeat forever
[spin setRepeatCount:HUGE_VALF];

// Add the animation to layer
[_layer1 addAnimation:spin forKey:@"spinAnimation"];
CAKeyframeAnima+on	
  
•  The	
  basic	
  anima+on	
  animates	
  from	
  one	
  value	
  
   to	
  second.	
  	
  
•  CAKeyFrameAnima+on	
  accepts	
  many	
  values,	
  
   an	
  NSArray	
  of	
  values.	
  
•  The	
  NSArray	
  is	
  set	
  as	
  the	
  values	
  property	
  of	
  a	
  
   CAKeyframeAnima+on	
  
Move	
  Layer	
  Example	
  
CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation
    animationWithKeyPath:@"position"];

NSMutableArray* locations = [NSMutableArray array];

// C API (CGPoint is struct)
CGPoint loc = CGPointMake(0.0, 0.0);

// Cast to Objective-C object
NSValue* value = [NSValue valueWithCGPoint:loc];

[locations addObject: value];
[locations addObject: [NSValue valueWithCGPoint:CGPointMake(150,150)]];
[locations addObject: [NSValue valueWithCGPoint:CGPointMake(100,350)]];

[moveAnim setValues: locations];
[moveAnim setDuration:5.0];
[moveAnim setRepeatCount:HUGE_VALF];
CAAnima+onGroup	
  
•  CAAnima+onGroup	
  holds	
  group	
  of	
  
   CAAnima+ons	
  
•  Several	
  anima+ons	
  done	
  concurrently	
  
•  Add	
  NSArray	
  of	
  anima+ons	
  to	
  
   CAAnima+onGroup	
  and	
  set	
  this	
  to	
  layer	
  
CAAnima+onGroup	
  
CAKeyframeAnimation *move =
  [CAKeyframeAnimation animationWithKeyPath:@"position"];

 ...

 CABasicAnimation *spin =
   [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
 [spin setToValue:[NSNumber numberWithFloat:M_PI*2.0]];
 [spin setDuration:1.0];
 [spin setRepeatCount:HUGE_VALF];

 CAAnimationGroup* group = [CAAnimationGroup animation];
 [group setAnimations:[NSArray arrayWithObjects:spin, move, nil]];
 [group setDuration:5.0];
 [group setRepeatCount:HUGE_VALF];
CATransi+on	
  
•  Transi+on	
  of	
  layer	
  on	
  and	
  off	
  screen	
  
•  UINaviga+onController	
  uses	
  CATransi+on	
  
•  Set	
  type	
  
    –  Fade,	
  MoveIn,	
  Push,	
  Reveal	
  
•  Set	
  subtype	
  (direc+on)	
  
    –  Le`,	
  right,	
  up,	
  boaom	
  
•  And	
  set	
  also	
  dura+on	
  

More Related Content

Similar to iOS Core Animation

CocoaHeads Paris - CATransaction: What the flush?!
CocoaHeads Paris - CATransaction: What the flush?!CocoaHeads Paris - CATransaction: What the flush?!
CocoaHeads Paris - CATransaction: What the flush?!amadour
 
Starting Core Animation
Starting Core AnimationStarting Core Animation
Starting Core AnimationJohn Wilker
 
Java Core | JavaFX 2.0: Great User Interfaces in Java | Simon Ritter
Java Core | JavaFX 2.0: Great User Interfaces in Java | Simon RitterJava Core | JavaFX 2.0: Great User Interfaces in Java | Simon Ritter
Java Core | JavaFX 2.0: Great User Interfaces in Java | Simon RitterJAX London
 
CSS3 TTA (Transform Transition Animation)
CSS3 TTA (Transform Transition Animation)CSS3 TTA (Transform Transition Animation)
CSS3 TTA (Transform Transition Animation)창석 한
 
Hi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreTextHi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreTextMugunth Kumar
 
Building animated UI with Core Animation
Building animated UI with Core AnimationBuilding animated UI with Core Animation
Building animated UI with Core AnimationMarco Zoffoli
 
Сергій Міськів, «SwiftUI: Animations»
Сергій Міськів, «SwiftUI: Animations»Сергій Міськів, «SwiftUI: Animations»
Сергій Міськів, «SwiftUI: Animations»Sigma Software
 
Crafting interactions with Core Animations, David Ortinau
Crafting interactions with Core Animations, David OrtinauCrafting interactions with Core Animations, David Ortinau
Crafting interactions with Core Animations, David OrtinauXamarin
 
iPhone dev intro
iPhone dev introiPhone dev intro
iPhone dev introVonbo
 
Beginning to iPhone development
Beginning to iPhone developmentBeginning to iPhone development
Beginning to iPhone developmentVonbo
 
Implementing CATiledLayer
Implementing CATiledLayerImplementing CATiledLayer
Implementing CATiledLayerJesse Collis
 
CATiled Layer - Melbourne Cocoheads February 2012
CATiled Layer - Melbourne Cocoheads February 2012CATiled Layer - Melbourne Cocoheads February 2012
CATiled Layer - Melbourne Cocoheads February 2012Jesse Collis
 
Android webinar class_4
Android webinar class_4Android webinar class_4
Android webinar class_4Edureka!
 
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)Chris Adamson
 
Enhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsEnhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsNaman Dwivedi
 
Core animation taobao
Core animation taobaoCore animation taobao
Core animation taobaoyarshure Kong
 

Similar to iOS Core Animation (20)

Animation in iOS
Animation in iOSAnimation in iOS
Animation in iOS
 
CocoaHeads Paris - CATransaction: What the flush?!
CocoaHeads Paris - CATransaction: What the flush?!CocoaHeads Paris - CATransaction: What the flush?!
CocoaHeads Paris - CATransaction: What the flush?!
 
Starting Core Animation
Starting Core AnimationStarting Core Animation
Starting Core Animation
 
Java Core | JavaFX 2.0: Great User Interfaces in Java | Simon Ritter
Java Core | JavaFX 2.0: Great User Interfaces in Java | Simon RitterJava Core | JavaFX 2.0: Great User Interfaces in Java | Simon Ritter
Java Core | JavaFX 2.0: Great User Interfaces in Java | Simon Ritter
 
CSS3 TTA (Transform Transition Animation)
CSS3 TTA (Transform Transition Animation)CSS3 TTA (Transform Transition Animation)
CSS3 TTA (Transform Transition Animation)
 
Hi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreTextHi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreText
 
Building animated UI with Core Animation
Building animated UI with Core AnimationBuilding animated UI with Core Animation
Building animated UI with Core Animation
 
Сергій Міськів, «SwiftUI: Animations»
Сергій Міськів, «SwiftUI: Animations»Сергій Міськів, «SwiftUI: Animations»
Сергій Міськів, «SwiftUI: Animations»
 
Crafting interactions with Core Animations, David Ortinau
Crafting interactions with Core Animations, David OrtinauCrafting interactions with Core Animations, David Ortinau
Crafting interactions with Core Animations, David Ortinau
 
Peint talk
Peint talkPeint talk
Peint talk
 
iPhone dev intro
iPhone dev introiPhone dev intro
iPhone dev intro
 
Beginning to iPhone development
Beginning to iPhone developmentBeginning to iPhone development
Beginning to iPhone development
 
Implementing CATiledLayer
Implementing CATiledLayerImplementing CATiledLayer
Implementing CATiledLayer
 
CATiled Layer - Melbourne Cocoheads February 2012
CATiled Layer - Melbourne Cocoheads February 2012CATiled Layer - Melbourne Cocoheads February 2012
CATiled Layer - Melbourne Cocoheads February 2012
 
Android webinar class_4
Android webinar class_4Android webinar class_4
Android webinar class_4
 
Intro to HTML5
Intro to HTML5Intro to HTML5
Intro to HTML5
 
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
 
Enhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsEnhancing UI/UX using Java animations
Enhancing UI/UX using Java animations
 
Core animation taobao
Core animation taobaoCore animation taobao
Core animation taobao
 
004
004004
004
 

More from Jussi Pohjolainen

libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferencesJussi Pohjolainen
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationJussi Pohjolainen
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDXJussi Pohjolainen
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript DevelopmentJussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame AnimationJussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame AnimationJussi Pohjolainen
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDXJussi Pohjolainen
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDXJussi Pohjolainen
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesJussi Pohjolainen
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platformJussi Pohjolainen
 

More from Jussi Pohjolainen (20)

Moved to Speakerdeck
Moved to SpeakerdeckMoved to Speakerdeck
Moved to Speakerdeck
 
Java Web Services
Java Web ServicesJava Web Services
Java Web Services
 
Box2D and libGDX
Box2D and libGDXBox2D and libGDX
Box2D and libGDX
 
libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and Preferences
 
libGDX: Tiled Maps
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame Animation
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
libGDX: Scene2D
libGDX: Scene2DlibGDX: Scene2D
libGDX: Scene2D
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: User Input
libGDX: User InputlibGDX: User Input
libGDX: User Input
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
 
Intro to Asha UI
Intro to Asha UIIntro to Asha UI
Intro to Asha UI
 

Recently uploaded

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 

Recently uploaded (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 

iOS Core Animation

  • 1. Core  Anima+on   Jussi  Pohjolainen  
  • 3. UIView  Anima+ons   •  Several  view  proper+es  can  be  animated   –  Anima+on:  change  property  over  +me   •  UIView  does  most  of  the  job   •  Two  ways   –  Block-­‐based  anima:ons  (recommended)   –  Begin/commit  anima+ons    
  • 4. Animatable  Proper+es   •  frame   •  bounds   •  center   •  transform   –  Rota+on,  Scale,  Move..   •  alpha   •  backgroundColor   •  contentStretch  
  • 5. UIView  Block  Methods  for  Anima+on   Animate  changes  to  one  or  more  views  using  the  specified  dura5on,  delay,  op5ons,  and   comple5on  handler. + animateWithDuration:delay:options:animations:completion: Animate  changes  to  one  or  more  views  using  the  specified  dura5on  and  comple5on  handler.   + animateWithDuration:animations:completion: Animate  changes  to  one  or  more  views  using  the  specified  dura5on. + animateWithDuration:animations: Creates  a  transi5on  anima5on  for  the  specified  container  view. + transitionWithView:duration:options:animations:completion: Creates  a  transi5on  anima5on  between  the  specified  views  using  the  given  parameters. + transitionFromView:toView:duration:options:completion:
  • 6. Op+ons   •  Lot  of  anima+on  op+ons   –  CurveEaseIn,  out,  linear   –  Repeat..   •  Can  be  combined  using  |   –  UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAutoreverse
  • 7. Anima+on  with  Blocks   - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [UIView animateWithDuration:5.0 animations:^{ [animatingView setAlpha:0]; [animatingView setCenter:CGPointMake(animatingView.center.x+50.0, animatingView.center.y+50.0)]; } completion:^(BOOL finished) { [animatingView removeFromSuperview]; } ]; }
  • 9. Core  Anima+on  Layer     •  Anima+on  is  an  important  part  of  iOS     •  Add  QuartzCore  framework  to  your  project   •  Use  classes     –  CALayer   •  When  drawing  using  layers,  drawing  is  hardware-­‐ accelerated   •  Layer  is  a  buffer  containing  a  bitmap   –  CAAnima+on    
  • 10. Implicit  Layer   •  Every  UIView  has  an  CALayer   –  When  UIView  draws  itself,  the  view  image  is  in   CALayer   •  View  creates  a  layer:  implicit  layer   –  Matching  view  hierarchy  and  layer  hierarchy  
  • 11. Explicit  Layer   •  To  create  a  explicit  layer,  just  create  instance   of  CALayer   •  Layer  has  bounds  and  posi+on   •  Posi+on  is  by  default  the  center  of  the  layer.   Uses  coordinates  of  the  superlayer’s   coordinate  system  
  • 12. Explicit  Layer   CALayer* layer = [[CALayer alloc] init]; // Setting bounds to layer CGRect bounds = CGRectMake(0.0, 0.0, 100.0, 100.0); [layer setBounds:bounds]; // Setting *center* position to layer (uses superlayer's coordinate system) CGPoint position = CGPointMake(50.0, 150.0); [layer setPosition:position]; // Setting color to layer UIColor* red = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.5]; // Cast from UIKit to Core Graphics CGColorRef redRef = [red CGColor]; [layer setBackgroundColor:redRef]; [[[self view] layer] addSublayer: layer];
  • 13. UIColor,  CGColorRef   UIImage,  CGImageRef?   •  QuartzCore  frame  and  Core  Graphics   framework  eist  on  both  iOS  and  Mac  OS  X   •  UIKit  exists  only  on  iOS   –  UIImage,  UIColor  …   •  Due  to  portability  QuartzCore  uses  classes  like   –  CGImageRef,  CGColorRef   •  UIKit  provides  methods  to  access  Core   Craphics  counterparts  
  • 14. Using  Image   // Create a UIImage UIImage* layerImage = [UIImage imageNamed:@"dude.png"]; // Get underlying CGImage CGImageRef image = [layerImage CGImage]; // CGImageRef => typecast struct CGImage* // To cast from C-pointer to Objective-C id, we use // __bridge [layer setContents: (__bridge id)(image)]; // Fill the layer and maintain the aspect ratio [layer setContentsGravity:kCAGravityResizeAspect]; [[[self view] layer] addSublayer: layer];
  • 15. ZPosi+on   •  Layers  exist  in  hierarchy   –  Can  have  sublayers   –  Each  layer  has  pointer  back  to  its  parent:   superlayer   •  Layer  draws  on  top  of  its  superlayer   •  What  about  siblings  and  overlapping?   –  Layer  has  property  zPosi+on   –  If  siblings  overlap,  layer  with  higher  zPosi+on  is   composed  on  top.  
  • 16. Example   // Layer 2 will be on top of layer1 [layer1 setZPosition:0.0]; [layer2 setZPosition:1.0]; // Set background color to layer2 UIColor* red = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.5]; CGColorRef redRef = [red CGColor]; [layer2 setBackgroundColor:redRef]; // add layers as siblings [[[self view] layer] addSublayer: layer1]; [[[self view] layer] addSublayer: layer2];
  • 17. Implicitly  Animatable  Proper+es   •  Several  CALayer  proper+es  are  implicitly   animatable   –  When  a  se?er  is  called,  proper5es  are  animated!   –  Calling  setPosi+on  will  animate  layer  from  a  to  b   •  The  animatable  property  changes  to  its   des+na+on  value  over  constant  +me  interval   •  Changing  property  while  being  animated   starts  another  anima+on:  anima+on  seems   slow    
  • 18.
  • 19. Disable  implicit  anima+on   •  To  disable  implicit  anima+on,  use  anima+on   transac+on   •  Batch  anima+ons  and  set  there  parameters,   like  dura+on  and  anima+on  curve   •  Set  begin  and  commit  to  CATransac+on  
  • 20.
  • 22. About  Anima+on   •  Anima+on  object  changes  over  :me   •  Instruc+on  set  that  can  be  added  to  a  CALayer   instance   •  When  instruc+ons  are  added  to  layer,  layer   begins  following  the  instruc+ons  of  the   anima+on.   •  Many  proper+es  can  be  animated:  opacity,   posi+on,  transform,  bounds  …  
  • 23. Anima+on  Classes   •  CAAnima+on  (Abstract)   –  CAPropertyAnima+on  (Abstract)   •  CABasicAnima:on   •  CAKeyFrameAnima:on   –  CAAnima:onGroup   –  CATransi:on  
  • 24. CABasicAnima+on   •  CABasicAnima+on  has  two  values   –  fromValue –  toValue –  (and  the  dura+on  from  CAAnimation)   •  Decide  the  property,  then  set  values   fromValue  to  toValue  and  set  dura+on  also  
  • 25. Spinning  Layer  Example   // Create CABasicAnimation and inform about the property // we are going to influence CABasicAnimation *spin = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; // Changes rotation (uses radians) [spin setToValue:[NSNumber numberWithFloat:M_PI*2.0]]; // Set duration to one second [spin setDuration:1.0]; // Repeat forever [spin setRepeatCount:HUGE_VALF]; // Add the animation to layer [_layer1 addAnimation:spin forKey:@"spinAnimation"];
  • 26.
  • 27. CAKeyframeAnima+on   •  The  basic  anima+on  animates  from  one  value   to  second.     •  CAKeyFrameAnima+on  accepts  many  values,   an  NSArray  of  values.   •  The  NSArray  is  set  as  the  values  property  of  a   CAKeyframeAnima+on  
  • 28. Move  Layer  Example   CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"]; NSMutableArray* locations = [NSMutableArray array]; // C API (CGPoint is struct) CGPoint loc = CGPointMake(0.0, 0.0); // Cast to Objective-C object NSValue* value = [NSValue valueWithCGPoint:loc]; [locations addObject: value]; [locations addObject: [NSValue valueWithCGPoint:CGPointMake(150,150)]]; [locations addObject: [NSValue valueWithCGPoint:CGPointMake(100,350)]]; [moveAnim setValues: locations]; [moveAnim setDuration:5.0]; [moveAnim setRepeatCount:HUGE_VALF];
  • 29.
  • 30. CAAnima+onGroup   •  CAAnima+onGroup  holds  group  of   CAAnima+ons   •  Several  anima+ons  done  concurrently   •  Add  NSArray  of  anima+ons  to   CAAnima+onGroup  and  set  this  to  layer  
  • 31. CAAnima+onGroup   CAKeyframeAnimation *move = [CAKeyframeAnimation animationWithKeyPath:@"position"]; ... CABasicAnimation *spin = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; [spin setToValue:[NSNumber numberWithFloat:M_PI*2.0]]; [spin setDuration:1.0]; [spin setRepeatCount:HUGE_VALF]; CAAnimationGroup* group = [CAAnimationGroup animation]; [group setAnimations:[NSArray arrayWithObjects:spin, move, nil]]; [group setDuration:5.0]; [group setRepeatCount:HUGE_VALF];
  • 32.
  • 33. CATransi+on   •  Transi+on  of  layer  on  and  off  screen   •  UINaviga+onController  uses  CATransi+on   •  Set  type   –  Fade,  MoveIn,  Push,  Reveal   •  Set  subtype  (direc+on)   –  Le`,  right,  up,  boaom   •  And  set  also  dura+on