SlideShare a Scribd company logo
Core Animation
                for iPhone



www.invasivecode.com   1   CocoaHeads, Barcelona, April 24, 2009
What’s that?

              Transforming smoothly an object’s visual
                      representation over time



          Import QuartzCore.framework in your project




www.invasivecode.com             2          CocoaHeads, Barcelona, April 24, 2009
CALayer


         • Every view is layer-backed
         • A cached copy of UIView’s appearance
         • Takes responsibility during animation




www.invasivecode.com           3          CocoaHeads, Barcelona, April 24, 2009
CALayer




www.invasivecode.com      4      CocoaHeads, Barcelona, April 24, 2009
Layer geometry




www.invasivecode.com         5    CocoaHeads, Barcelona, April 24, 2009
Layer transformations
 You can use matrix transformations
 It is a CGFloat 4x4 matrix

 trasform and sublayerTransform
         Function                                                                   Use
 CATranform3DMakeTranslation   Returns a transform that translates by '(tx, ty, tz)'. t' = [1 0 0 0; 0 1 0 0; 0 0 1 0; tx ty tz 1].
 CATranform3DTranslate         Translate 't' by '(tx, ty, tz)' and return the result: * t' = translate(tx, ty, tz) * t.
 CATranform3DMakeScale         Returns a transform that scales by `(sx, sy, sz)': * t' = [sx 0 0 0; 0 sy 0 0; 0 0 sz 0; 0 0 0 1].
 CATranform3DScale             Scale 't' by '(sx, sy, sz)' and return the result: * t' = scale(sx, sy, sz) * t.
                               Returns a transform that rotates by 'angle' radians about the vector '(x, y, z)'. If the vector has
 CATranform3DMakeRotation
                               length zero the identity transform is returned.
                               Rotate 't' by 'angle' radians about the vector '(x, y, z)' and return the result. t' = rotation(angle, x,
 CATranform3DRotate
                               y, z) * t.




www.invasivecode.com                                               6                            CocoaHeads, Barcelona, April 24, 2009
Animation types


         • Implicit animation
         • Explicit animation
         • Key-frame animation



www.invasivecode.com          7    CocoaHeads, Barcelona, April 24, 2009
Implicit animations

    • The simplest type of animation
    • Tell UIView that it should animate and change its
      properties

   The animation starts when commitAnimations is sent
                 [UIView beginAnimations:nil context:nil];

                 // your code here

                 [UIVIew commitAnimations];



www.invasivecode.com                 8           CocoaHeads, Barcelona, April 24, 2009
Implicit animations
      Defined in UIView          + beginAnimations:context:
                                + commitAnimations
                                + setAnimationStartDate:
                                + setAnimationsEnabled:
                                + setAnimationDelegate:
                                + setAnimationWillStartSelector:
                                + setAnimationDidStopSelector:
                                + setAnimationDuration:
                                + setAnimationDelay:
                                + setAnimationCurve:
                                + setAnimationRepeatCount:
                                + setAnimationRepeatAutoreverses:
                                + setAnimationBeginsFromCurrentState:
                                + setAnimationTransition:forView:cache:
                                + areAnimationsEnabled



              All the properties change concurrently

www.invasivecode.com              9              CocoaHeads, Barcelona, April 24, 2009
Explicit animations
     • Basic Animations: CABasicAnimation
     • You can specify the animation for each layer property
     • Create an animation with
       +animationWithKeyPath:
     • Apply the animation sending
       addAnimation:forKey
     • Stop the animation sending:
       removeAnimationForKey:

www.invasivecode.com           10         CocoaHeads, Barcelona, April 24, 2009
Objects
                                  CAAnimation             <CAMediaTiming>




    CAAnimationGroup

                                                          CATransition

                            CAPropertyAnimation




               CABasicAnimation                 CAKeyframeAnimation


www.invasivecode.com                    11             CocoaHeads, Barcelona, April 24, 2009
CAMediaTimingFunction




www.invasivecode.com   12   CocoaHeads, Barcelona, April 24, 2009
View Transitions



www.invasivecode.com   13   CocoaHeads, Barcelona, April 24, 2009
What is it?

      • Special kind of animation


        #import <QuartzCore/CAAnimation.h>
        CATransition *aTransition = [CATransition animation];




www.invasivecode.com             14           CocoaHeads, Barcelona, April 24, 2009
Animation type

                aTransition.type = kCATransitionMoveIn;



         Animation type                        Description
       kCATransitionFade     Fade from one view to the next

       kCATransitionPush     Push the old view out, bringing the new one in

       kCATransitionReveal   Move the old view out revealing the new one

       kCATransitionMoveIn   Move the new view in over the old one




www.invasivecode.com                     15              CocoaHeads, Barcelona, April 24, 2009
Animation subtype

           aTransition.subtype = kCATransitionFromLeft;


                Animation subtype                Description
             kCATransitionFromTop      New views slides from top
             kCATransitionFromBottom   New views slides from bottom

             kCATransitionFromRight    New views slides from right

             kCATransitionFromLeft     New views slides from left




www.invasivecode.com                   16                CocoaHeads, Barcelona, April 24, 2009
Timing and duration

   aTransition.timingFunction = UIViewAnimationCurveEaseIn;

                       Timing                             Description
          UIViewAnimationCurveEaseInOut   Animation is slow at the beginning and the end
          UIViewAnimationCurveEaseIn      Animation speed increase at the beginning
          UIViewAnimationCurveEaseOut     Animation speed decrease at the end
          UIViewAnimationCurveLinear      Uniform speed



                  aTransition.duration = 0.5; // seconds




www.invasivecode.com                          17                   CocoaHeads, Barcelona, April 24, 2009
Animate a view


   [self.view.superview.layer addAnimation:myTransition forKey:nil];




www.invasivecode.com               18           CocoaHeads, Barcelona, April 24, 2009

More Related Content

Similar to Core Animation (20)

KEY
Artdm170 week6 scripting_motion
Gilbert Guerrero
 
KEY
Artdm170 Week6 Scripting Motion
Gilbert Guerrero
 
PPTX
Java Core | JavaFX 2.0: Great User Interfaces in Java | Simon Ritter
JAX London
 
PDF
iOS Core Animation
Jussi Pohjolainen
 
PDF
Core Animation
Bob McCune
 
KEY
Core animation
Weizhong Yang
 
PDF
UI Dynamics
SV.CO
 
PDF
Crafting interactions with Core Animations, David Ortinau
Xamarin
 
PDF
Optimized Rendering Techniques for Mobile VR
DevGAMM Conference
 
PDF
Mapping the world with Twitter
carlo zapponi
 
PDF
Mockito a simple, intuitive mocking framework
Phat VU
 
PPTX
A practical intro to BabylonJS
HansRontheWeb
 
PDF
Master of Canvas
Mima Yuki
 
PDF
Vue in Motion
Rachel Nabors
 
PPT
Rotoscope inthebrowserppt billy
nimbleltd
 
DOCX
Android canvas-chapter20
Dr. Ramkumar Lakshminarayanan
 
DOCX
Eye ball cursor movement using opencv
Venkat Projects
 
PDF
Core animation taobao
yarshure Kong
 
PDF
MongoUK 2011 - Rplacing RabbitMQ with MongoDB
Boxed Ice
 
PPT
Animation Framework: A Step Towards Modern UIs
account inactive
 
Artdm170 week6 scripting_motion
Gilbert Guerrero
 
Artdm170 Week6 Scripting Motion
Gilbert Guerrero
 
Java Core | JavaFX 2.0: Great User Interfaces in Java | Simon Ritter
JAX London
 
iOS Core Animation
Jussi Pohjolainen
 
Core Animation
Bob McCune
 
Core animation
Weizhong Yang
 
UI Dynamics
SV.CO
 
Crafting interactions with Core Animations, David Ortinau
Xamarin
 
Optimized Rendering Techniques for Mobile VR
DevGAMM Conference
 
Mapping the world with Twitter
carlo zapponi
 
Mockito a simple, intuitive mocking framework
Phat VU
 
A practical intro to BabylonJS
HansRontheWeb
 
Master of Canvas
Mima Yuki
 
Vue in Motion
Rachel Nabors
 
Rotoscope inthebrowserppt billy
nimbleltd
 
Android canvas-chapter20
Dr. Ramkumar Lakshminarayanan
 
Eye ball cursor movement using opencv
Venkat Projects
 
Core animation taobao
yarshure Kong
 
MongoUK 2011 - Rplacing RabbitMQ with MongoDB
Boxed Ice
 
Animation Framework: A Step Towards Modern UIs
account inactive
 

Recently uploaded (20)

PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PPTX
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Market Insight : ETH Dominance Returns
CIFDAQ
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PPTX
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PPTX
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Market Insight : ETH Dominance Returns
CIFDAQ
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
Ad

Core Animation

  • 1. Core Animation for iPhone www.invasivecode.com 1 CocoaHeads, Barcelona, April 24, 2009
  • 2. What’s that? Transforming smoothly an object’s visual representation over time Import QuartzCore.framework in your project www.invasivecode.com 2 CocoaHeads, Barcelona, April 24, 2009
  • 3. CALayer • Every view is layer-backed • A cached copy of UIView’s appearance • Takes responsibility during animation www.invasivecode.com 3 CocoaHeads, Barcelona, April 24, 2009
  • 4. CALayer www.invasivecode.com 4 CocoaHeads, Barcelona, April 24, 2009
  • 5. Layer geometry www.invasivecode.com 5 CocoaHeads, Barcelona, April 24, 2009
  • 6. Layer transformations You can use matrix transformations It is a CGFloat 4x4 matrix trasform and sublayerTransform Function Use CATranform3DMakeTranslation Returns a transform that translates by '(tx, ty, tz)'. t' = [1 0 0 0; 0 1 0 0; 0 0 1 0; tx ty tz 1]. CATranform3DTranslate Translate 't' by '(tx, ty, tz)' and return the result: * t' = translate(tx, ty, tz) * t. CATranform3DMakeScale Returns a transform that scales by `(sx, sy, sz)': * t' = [sx 0 0 0; 0 sy 0 0; 0 0 sz 0; 0 0 0 1]. CATranform3DScale Scale 't' by '(sx, sy, sz)' and return the result: * t' = scale(sx, sy, sz) * t. Returns a transform that rotates by 'angle' radians about the vector '(x, y, z)'. If the vector has CATranform3DMakeRotation length zero the identity transform is returned. Rotate 't' by 'angle' radians about the vector '(x, y, z)' and return the result. t' = rotation(angle, x, CATranform3DRotate y, z) * t. www.invasivecode.com 6 CocoaHeads, Barcelona, April 24, 2009
  • 7. Animation types • Implicit animation • Explicit animation • Key-frame animation www.invasivecode.com 7 CocoaHeads, Barcelona, April 24, 2009
  • 8. Implicit animations • The simplest type of animation • Tell UIView that it should animate and change its properties The animation starts when commitAnimations is sent [UIView beginAnimations:nil context:nil]; // your code here [UIVIew commitAnimations]; www.invasivecode.com 8 CocoaHeads, Barcelona, April 24, 2009
  • 9. Implicit animations Defined in UIView + beginAnimations:context: + commitAnimations + setAnimationStartDate: + setAnimationsEnabled: + setAnimationDelegate: + setAnimationWillStartSelector: + setAnimationDidStopSelector: + setAnimationDuration: + setAnimationDelay: + setAnimationCurve: + setAnimationRepeatCount: + setAnimationRepeatAutoreverses: + setAnimationBeginsFromCurrentState: + setAnimationTransition:forView:cache: + areAnimationsEnabled All the properties change concurrently www.invasivecode.com 9 CocoaHeads, Barcelona, April 24, 2009
  • 10. Explicit animations • Basic Animations: CABasicAnimation • You can specify the animation for each layer property • Create an animation with +animationWithKeyPath: • Apply the animation sending addAnimation:forKey • Stop the animation sending: removeAnimationForKey: www.invasivecode.com 10 CocoaHeads, Barcelona, April 24, 2009
  • 11. Objects CAAnimation <CAMediaTiming> CAAnimationGroup CATransition CAPropertyAnimation CABasicAnimation CAKeyframeAnimation www.invasivecode.com 11 CocoaHeads, Barcelona, April 24, 2009
  • 12. CAMediaTimingFunction www.invasivecode.com 12 CocoaHeads, Barcelona, April 24, 2009
  • 13. View Transitions www.invasivecode.com 13 CocoaHeads, Barcelona, April 24, 2009
  • 14. What is it? • Special kind of animation #import <QuartzCore/CAAnimation.h> CATransition *aTransition = [CATransition animation]; www.invasivecode.com 14 CocoaHeads, Barcelona, April 24, 2009
  • 15. Animation type aTransition.type = kCATransitionMoveIn; Animation type Description kCATransitionFade Fade from one view to the next kCATransitionPush Push the old view out, bringing the new one in kCATransitionReveal Move the old view out revealing the new one kCATransitionMoveIn Move the new view in over the old one www.invasivecode.com 15 CocoaHeads, Barcelona, April 24, 2009
  • 16. Animation subtype aTransition.subtype = kCATransitionFromLeft; Animation subtype Description kCATransitionFromTop New views slides from top kCATransitionFromBottom New views slides from bottom kCATransitionFromRight New views slides from right kCATransitionFromLeft New views slides from left www.invasivecode.com 16 CocoaHeads, Barcelona, April 24, 2009
  • 17. Timing and duration aTransition.timingFunction = UIViewAnimationCurveEaseIn; Timing Description UIViewAnimationCurveEaseInOut Animation is slow at the beginning and the end UIViewAnimationCurveEaseIn Animation speed increase at the beginning UIViewAnimationCurveEaseOut Animation speed decrease at the end UIViewAnimationCurveLinear Uniform speed aTransition.duration = 0.5; // seconds www.invasivecode.com 17 CocoaHeads, Barcelona, April 24, 2009
  • 18. Animate a view [self.view.superview.layer addAnimation:myTransition forKey:nil]; www.invasivecode.com 18 CocoaHeads, Barcelona, April 24, 2009