SlideShare ist ein Scribd-Unternehmen logo
1 von 33
Downloaden Sie, um offline zu lesen
Creating Animated UIs with

Core Animation

              http://bobmccune.com
Agenda
• Overview of Core Animation
  • Layers
  • Animations
  • Transformations
• Practical Animations
  • UIKit Animations
  • New features in iOS 4
Why is animation important?
Why is animation important?
• Provides Context
• Aides in Learning
• Natural Interface
• Consistency
Core Animation
The “Magic” in iOS
 • Lightweight, high-performance compositing
   • Hardware accelerated
   • Animations run on separate threads
 • Simple, familiar programming model
 • Powerful, yet easy to use
Core Animation Architecture
                              Rendered
             UIKit             in GPU


         Core Animation


           Open GL


           Hardware
Understanding Layers
Core Animation Layers
• Foundational component of Core Animation
  • Found in Quartz Core
• Programming model similar to views
  •   addSublayer
  •   layoutSublayers
  •   insertSublayer:atIndex:
• 2 1/2 D Model
  • Transform 2D plane in 3D space
• Works with Core Graphics types
CALayer Content
• Set contents property
  •   CGImageRef
• Draw content in CGContextRef
  • Delegation: drawLayer:inContext:
  • Subclass: drawInContext:
• Specialized Layers:
  • CAShapeLayer, CATextLayer,
      AVPlayerLayer, CAGradientLayer, etc.
CALayer Example
UIImage *image = [UIImage imageNamed:@"ca_logo.png"];

CALayer *logoLayer = [CALayer layer];
logoLayer.bounds =
     CGRectMake(0, 0, image.size.width, image.size.height);
logoLayer.borderColor = [UIColor whiteColor].CGColor;
logoLayer.border = 1.0;
logoLayer.position = CGPointMake(160, 180);
logoLayer.contents = (id)image.CGImage;
Layer Geometry
                    X
• bounds
• position
• transform     Y
• anchorPoint
                                   anchorPoint
• frame

                                   bounds


                        position
Creating Animations
Implicit Animations
 • Almost all CALayer properties are animatable
 • Property changes trigger implicit animations
   • Animation duration over 1/4 second
   • Uses linear animation curve by default
   • Multiple changes batched into transaction



    megaManLayer.position = CGPointMake(200, 100);
Explicit Animations
 • Core Animation provides support for explicit
  animations
   • Provides more fine-grained control
 • Primary classes
   •   CABasicAnimation
   •   CAKeyframeAnimation
   •   CAAnimationGroup
Basic Animations
CABasicAnimation
 • Create an animation for a keyPath:
   •   @"position"
   •   @"transform.rotation.z"
   •   @"backgroundColor"
 • Set its toValue and fromValue properties
 • Add the animation to the layer to animate
CABasicAnimation
Example

CABasicAnimation *animation =
  [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.fromValue = [NSNumber numberWithFloat:1.0];
animation.toValue = [NSNumber numberWithFloat:0.0];
animation.duration = 1.0;
[layer addAnimation:animation forKey:@"animateOpacity"];
CABasicAnimation
Example

CABasicAnimation *animation =            Gotcha Alert
  [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.fromValue = [NSNumber numberWithFloat:1.0];
animation.toValue = [NSNumber numberWithFloat:0.0];
animation.duration = 1.0;
layer.opacity = 0.0;      Update the model to make it stick
[layer addAnimation:animation forKey:@"animateOpacity"];
Key Frame Animations
CAKeyframeAnimation
 • Provides more advanced animation behavior
 • Animate across collection of "key frames"
   • path (CGPathRef)
   • values (NSArray of values)
 • Can define timing of each point or value
CAKeyframeAnimation
Example
CAKeyframeAnimation *animation =
  [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.path = path; // CGPathRef
animation.duration = 2.0f;
animation.rotationMode = kCAAnimationRotateAuto;
[layer addAnimation:animation forKey:@"animatePosition"];
Transforming Layers
CATransform3D
• Layer transformations with CATransform3D
  • Similar to CGAffineTransform
  • Transforms can be performed in X,Y, and Z
• Transformations created using:
  • CATransform3DScale()
  • CATransform3DRotate()
  • CATransform3DTranslate()
• Can set transform and sublayerTransform
CATransform3D
Example
CABasicAnimation *animation =
    [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

// Animate 2, counter-clockwise 360 degree rotations
CGFloat radians = (2 * M_PI) * -2
animation.toValue = [NSNumber numberWithFloat:radians];
animation.duration = 0.75f;

[layer addAnimation:animation forKey:@"animateRotation"];
Animation Demos
UIKit Animations
UIView Animations
• UIView is a lightweight wrapper over CALayer
  • Every view has an associated CALayer
  • Override layerClass class method to change
   instance
• UIKit provides support for common animations
  • Behavior for free with animated:YES
  • Low cost view transitions
• Uses Core Animation under the hood
Core Animation and UIKit
• View and Layers are complimentary
• CA layers provide no event handling
  • Manual hit testing
  • No gesture recognizers
• Layers provides more animatable properties
• Layers provide additional capabilities
  • cornerRadius, border, shadows
• Need Core Animation to move beyond
  stock animations
Animating Views in iOS < 4.0
[UIView beginAnimations:@"fadeMe" context:NULL];
[UIView setAnimationDuration:1.0];
self.megaManView.alpha = 0.0f;
[UIView commitAnimations];
View Animations in iOS 4
[UIView animateWithDuration:1.0 animations:^{
	 self.megaManView.alpha = 0.0f;	
}];
Blocks-based Animation API
animateWithDuration:
         animations:
                       Simple Animations

animateWithDuration:
         animations:   Simple Animations with
         completion:   completion callback
animateWithDuration:
              delay:   More complex with
            options:
         animations:   customizable options
         completion:
Blocks-based Animation API
animateWithDuration:
         animations:
                       Simple Animations

animateWithDuration:
         animations:   Simple Animations with
         completion:   completion callback
animateWithDuration:
              delay:   More complex with
            options:
         animations:   customizable options
         completion:
Animation Options
UIViewAnimationOption
 • Bit mask to specify animation behavior
   • Repeating and autoreverse behavior
   • Enabling user interaction
     • Blocks-based API defaults to NO
 • Specifying animation curves
 • Beginning an animation from current state
 • Property inheritance
View Transitions
 • UIView provides common animated transitions
   • Reveals, Slides, Flips, Curls, etc.
 • Transitions performed using:
   •   transitionWithView:
   •   transitionFromView:toView:
 • Transitions behavior customized with
  animation options mask
Animation Demos
Summary
• CA provides powerful, easy to use API
  • Lightweight
  • Hardware accelerated
  • Robust animations without OpenGL
• UIView and Core Animation
  • UIKit provides support for common
      animations
  •   Can use Core Animation directly where more
      power and flexibility is needed

Weitere ähnliche Inhalte

Was ist angesagt?

Google I/O 2013 - Android Graphics Performance
Google I/O 2013 - Android Graphics PerformanceGoogle I/O 2013 - Android Graphics Performance
Google I/O 2013 - Android Graphics PerformanceDouO
 
Android animation
Android animationAndroid animation
Android animationKrazy Koder
 
Android High performance in GPU using opengles and renderscript
Android High performance in GPU using opengles and renderscriptAndroid High performance in GPU using opengles and renderscript
Android High performance in GPU using opengles and renderscriptArvind Devaraj
 
Android App Development - 12 animations
Android App Development - 12 animationsAndroid App Development - 12 animations
Android App Development - 12 animationsDiego Grancini
 
[Android] Android Animation
[Android] Android Animation[Android] Android Animation
[Android] Android AnimationNikmesoft Ltd
 
Android Training (Animation)
Android Training (Animation)Android Training (Animation)
Android Training (Animation)Khaled Anaqwa
 
Introduction to Android Animations
Introduction to Android AnimationsIntroduction to Android Animations
Introduction to Android AnimationsXamarin
 
Android animations
Android animationsAndroid animations
Android animationsKumar
 
OpenGLES Android Graphics
OpenGLES Android GraphicsOpenGLES Android Graphics
OpenGLES Android GraphicsArvind Devaraj
 
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
 
Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)Marakana Inc.
 
FMX2013: Butterfly Effect
FMX2013: Butterfly EffectFMX2013: Butterfly Effect
FMX2013: Butterfly EffectRenaldas Zioma
 
Introduction to Skia by Ryan Chou @20141008
Introduction to Skia by Ryan Chou @20141008Introduction to Skia by Ryan Chou @20141008
Introduction to Skia by Ryan Chou @20141008Ryan Chou
 

Was ist angesagt? (17)

Google I/O 2013 - Android Graphics Performance
Google I/O 2013 - Android Graphics PerformanceGoogle I/O 2013 - Android Graphics Performance
Google I/O 2013 - Android Graphics Performance
 
Android animation
Android animationAndroid animation
Android animation
 
Android High performance in GPU using opengles and renderscript
Android High performance in GPU using opengles and renderscriptAndroid High performance in GPU using opengles and renderscript
Android High performance in GPU using opengles and renderscript
 
Android App Development - 12 animations
Android App Development - 12 animationsAndroid App Development - 12 animations
Android App Development - 12 animations
 
[Android] Android Animation
[Android] Android Animation[Android] Android Animation
[Android] Android Animation
 
Hardware Accelerated 2D Rendering for Android
Hardware Accelerated 2D Rendering for AndroidHardware Accelerated 2D Rendering for Android
Hardware Accelerated 2D Rendering for Android
 
Android animation theory
Android animation theoryAndroid animation theory
Android animation theory
 
Android Training (Animation)
Android Training (Animation)Android Training (Animation)
Android Training (Animation)
 
Introduction to Android Animations
Introduction to Android AnimationsIntroduction to Android Animations
Introduction to Android Animations
 
Android animations
Android animationsAndroid animations
Android animations
 
Android Animator
Android AnimatorAndroid Animator
Android Animator
 
OpenGLES Android Graphics
OpenGLES Android GraphicsOpenGLES Android Graphics
OpenGLES Android Graphics
 
I phone 6
I phone 6I phone 6
I phone 6
 
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
 
Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)
 
FMX2013: Butterfly Effect
FMX2013: Butterfly EffectFMX2013: Butterfly Effect
FMX2013: Butterfly Effect
 
Introduction to Skia by Ryan Chou @20141008
Introduction to Skia by Ryan Chou @20141008Introduction to Skia by Ryan Chou @20141008
Introduction to Skia by Ryan Chou @20141008
 

Andere mochten auch

Objective-C for Java Developers
Objective-C for Java DevelopersObjective-C for Java Developers
Objective-C for Java DevelopersBob McCune
 
Creating Container View Controllers
Creating Container View ControllersCreating Container View Controllers
Creating Container View ControllersBob McCune
 
Composing and Editing Media with AV Foundation
Composing and Editing Media with AV FoundationComposing and Editing Media with AV Foundation
Composing and Editing Media with AV FoundationBob McCune
 
Drawing with Quartz on iOS
Drawing with Quartz on iOSDrawing with Quartz on iOS
Drawing with Quartz on iOSBob McCune
 
Master Video with AV Foundation
Master Video with AV FoundationMaster Video with AV Foundation
Master Video with AV FoundationBob McCune
 
Quartz 2D with Swift 3
Quartz 2D with Swift 3Quartz 2D with Swift 3
Quartz 2D with Swift 3Bob McCune
 
After Effects CC with Cinema 4D Lite
After Effects CC with Cinema 4D LiteAfter Effects CC with Cinema 4D Lite
After Effects CC with Cinema 4D Liteayman diab
 
Starting Core Animation
Starting Core AnimationStarting Core Animation
Starting Core AnimationJohn Wilker
 
Building Modern Audio Apps with AVAudioEngine
Building Modern Audio Apps with AVAudioEngineBuilding Modern Audio Apps with AVAudioEngine
Building Modern Audio Apps with AVAudioEngineBob McCune
 
Mastering Media with AV Foundation
Mastering Media with AV FoundationMastering Media with AV Foundation
Mastering Media with AV FoundationChris Adamson
 
Open GL Animation
Open GL  AnimationOpen GL  Animation
Open GL AnimationKiran Munir
 
iOS Developer Interview Questions
iOS Developer Interview QuestionsiOS Developer Interview Questions
iOS Developer Interview QuestionsClark Davidson
 
20 iOS developer interview questions
20 iOS developer interview questions20 iOS developer interview questions
20 iOS developer interview questionsArc & Codementor
 
try! Swift - Advanced Graphics with Core Animation
try! Swift - Advanced Graphics with Core Animationtry! Swift - Advanced Graphics with Core Animation
try! Swift - Advanced Graphics with Core AnimationTim Oliver
 
Designing better user interfaces
Designing better user interfacesDesigning better user interfaces
Designing better user interfacesJohan Ronsse
 
iOS Coding Best Practices
iOS Coding Best PracticesiOS Coding Best Practices
iOS Coding Best PracticesJean-Luc David
 
Photoshop tools and their functions
Photoshop tools and their functionsPhotoshop tools and their functions
Photoshop tools and their functionsGener Evangelista
 
iOS design: a case study
iOS design: a case studyiOS design: a case study
iOS design: a case studyJohan Ronsse
 
iOS Scroll Performance
iOS Scroll PerformanceiOS Scroll Performance
iOS Scroll PerformanceKyle Sherman
 

Andere mochten auch (20)

Objective-C for Java Developers
Objective-C for Java DevelopersObjective-C for Java Developers
Objective-C for Java Developers
 
Creating Container View Controllers
Creating Container View ControllersCreating Container View Controllers
Creating Container View Controllers
 
Composing and Editing Media with AV Foundation
Composing and Editing Media with AV FoundationComposing and Editing Media with AV Foundation
Composing and Editing Media with AV Foundation
 
Drawing with Quartz on iOS
Drawing with Quartz on iOSDrawing with Quartz on iOS
Drawing with Quartz on iOS
 
Master Video with AV Foundation
Master Video with AV FoundationMaster Video with AV Foundation
Master Video with AV Foundation
 
Quartz 2D with Swift 3
Quartz 2D with Swift 3Quartz 2D with Swift 3
Quartz 2D with Swift 3
 
After Effects CC with Cinema 4D Lite
After Effects CC with Cinema 4D LiteAfter Effects CC with Cinema 4D Lite
After Effects CC with Cinema 4D Lite
 
Starting Core Animation
Starting Core AnimationStarting Core Animation
Starting Core Animation
 
Building Modern Audio Apps with AVAudioEngine
Building Modern Audio Apps with AVAudioEngineBuilding Modern Audio Apps with AVAudioEngine
Building Modern Audio Apps with AVAudioEngine
 
Mastering Media with AV Foundation
Mastering Media with AV FoundationMastering Media with AV Foundation
Mastering Media with AV Foundation
 
Open GL Animation
Open GL  AnimationOpen GL  Animation
Open GL Animation
 
iOS Developer Interview Questions
iOS Developer Interview QuestionsiOS Developer Interview Questions
iOS Developer Interview Questions
 
20 iOS developer interview questions
20 iOS developer interview questions20 iOS developer interview questions
20 iOS developer interview questions
 
Graphics Libraries
Graphics LibrariesGraphics Libraries
Graphics Libraries
 
try! Swift - Advanced Graphics with Core Animation
try! Swift - Advanced Graphics with Core Animationtry! Swift - Advanced Graphics with Core Animation
try! Swift - Advanced Graphics with Core Animation
 
Designing better user interfaces
Designing better user interfacesDesigning better user interfaces
Designing better user interfaces
 
iOS Coding Best Practices
iOS Coding Best PracticesiOS Coding Best Practices
iOS Coding Best Practices
 
Photoshop tools and their functions
Photoshop tools and their functionsPhotoshop tools and their functions
Photoshop tools and their functions
 
iOS design: a case study
iOS design: a case studyiOS design: a case study
iOS design: a case study
 
iOS Scroll Performance
iOS Scroll PerformanceiOS Scroll Performance
iOS Scroll Performance
 

Ähnlich wie Creating Animated UIs with Core Animation

Choosing your animation adventure - Generate NYC 2018
Choosing your animation adventure  - Generate NYC 2018Choosing your animation adventure  - Generate NYC 2018
Choosing your animation adventure - Generate NYC 2018Val Head
 
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
 
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
 
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
 
Сергій Міськів, «SwiftUI: Animations»
Сергій Міськів, «SwiftUI: Animations»Сергій Міськів, «SwiftUI: Animations»
Сергій Міськів, «SwiftUI: Animations»Sigma Software
 
Demystifying Angular Animations
Demystifying Angular AnimationsDemystifying Angular Animations
Demystifying Angular AnimationsGil Fink
 
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
 
CATiled Layer - Melbourne Cocoheads February 2012
CATiled Layer - Melbourne Cocoheads February 2012CATiled Layer - Melbourne Cocoheads February 2012
CATiled Layer - Melbourne Cocoheads February 2012Jesse Collis
 
Choosing your animation adventure - Ffronteers Conf 2017
Choosing your animation adventure - Ffronteers Conf 2017Choosing your animation adventure - Ffronteers Conf 2017
Choosing your animation adventure - Ffronteers Conf 2017Val Head
 
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014Chris Adamson
 
Awesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescriptAwesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescriptAmir Barylko
 
ボタンアニメーションに三角関数を導入して徒労に終わった話
ボタンアニメーションに三角関数を導入して徒労に終わった話ボタンアニメーションに三角関数を導入して徒労に終わった話
ボタンアニメーションに三角関数を導入して徒労に終わった話Naoya Shiga
 
Celtra builder features - Motion Graphics
Celtra builder features - Motion GraphicsCeltra builder features - Motion Graphics
Celtra builder features - Motion GraphicsCeltra Inc
 
Motion design in FIori
Motion design in FIoriMotion design in FIori
Motion design in FIoriRoman Rommel
 
Core animation taobao
Core animation taobaoCore animation taobao
Core animation taobaoyarshure Kong
 
Programming iOS in C#
Programming iOS in C#Programming iOS in C#
Programming iOS in C#Frank Krueger
 

Ähnlich wie Creating Animated UIs with Core Animation (20)

Core animation
Core animationCore animation
Core animation
 
iOS Core Animation
iOS Core AnimationiOS Core Animation
iOS Core Animation
 
Choosing your animation adventure - Generate NYC 2018
Choosing your animation adventure  - Generate NYC 2018Choosing your animation adventure  - Generate NYC 2018
Choosing your animation adventure - Generate NYC 2018
 
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
 
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
 
CocoaHeads Paris - CATransaction: What the flush?!
CocoaHeads Paris - CATransaction: What the flush?!CocoaHeads Paris - CATransaction: What the flush?!
CocoaHeads Paris - CATransaction: What the flush?!
 
Core Image
Core ImageCore Image
Core Image
 
Сергій Міськів, «SwiftUI: Animations»
Сергій Міськів, «SwiftUI: Animations»Сергій Міськів, «SwiftUI: Animations»
Сергій Міськів, «SwiftUI: Animations»
 
Demystifying Angular Animations
Demystifying Angular AnimationsDemystifying Angular Animations
Demystifying Angular Animations
 
Peint talk
Peint talkPeint talk
Peint talk
 
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)
 
CATiled Layer - Melbourne Cocoheads February 2012
CATiled Layer - Melbourne Cocoheads February 2012CATiled Layer - Melbourne Cocoheads February 2012
CATiled Layer - Melbourne Cocoheads February 2012
 
Choosing your animation adventure - Ffronteers Conf 2017
Choosing your animation adventure - Ffronteers Conf 2017Choosing your animation adventure - Ffronteers Conf 2017
Choosing your animation adventure - Ffronteers Conf 2017
 
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014
 
Awesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescriptAwesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescript
 
ボタンアニメーションに三角関数を導入して徒労に終わった話
ボタンアニメーションに三角関数を導入して徒労に終わった話ボタンアニメーションに三角関数を導入して徒労に終わった話
ボタンアニメーションに三角関数を導入して徒労に終わった話
 
Celtra builder features - Motion Graphics
Celtra builder features - Motion GraphicsCeltra builder features - Motion Graphics
Celtra builder features - Motion Graphics
 
Motion design in FIori
Motion design in FIoriMotion design in FIori
Motion design in FIori
 
Core animation taobao
Core animation taobaoCore animation taobao
Core animation taobao
 
Programming iOS in C#
Programming iOS in C#Programming iOS in C#
Programming iOS in C#
 

Kürzlich hochgeladen

React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...itnewsafrica
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialJoão Esperancinha
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 

Kürzlich hochgeladen (20)

React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorial
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 

Creating Animated UIs with Core Animation

  • 1. Creating Animated UIs with Core Animation http://bobmccune.com
  • 2. Agenda • Overview of Core Animation • Layers • Animations • Transformations • Practical Animations • UIKit Animations • New features in iOS 4
  • 3. Why is animation important?
  • 4. Why is animation important? • Provides Context • Aides in Learning • Natural Interface • Consistency
  • 5. Core Animation The “Magic” in iOS • Lightweight, high-performance compositing • Hardware accelerated • Animations run on separate threads • Simple, familiar programming model • Powerful, yet easy to use
  • 6. Core Animation Architecture Rendered UIKit in GPU Core Animation Open GL Hardware
  • 8. Core Animation Layers • Foundational component of Core Animation • Found in Quartz Core • Programming model similar to views • addSublayer • layoutSublayers • insertSublayer:atIndex: • 2 1/2 D Model • Transform 2D plane in 3D space • Works with Core Graphics types
  • 9. CALayer Content • Set contents property • CGImageRef • Draw content in CGContextRef • Delegation: drawLayer:inContext: • Subclass: drawInContext: • Specialized Layers: • CAShapeLayer, CATextLayer, AVPlayerLayer, CAGradientLayer, etc.
  • 10. CALayer Example UIImage *image = [UIImage imageNamed:@"ca_logo.png"]; CALayer *logoLayer = [CALayer layer]; logoLayer.bounds = CGRectMake(0, 0, image.size.width, image.size.height); logoLayer.borderColor = [UIColor whiteColor].CGColor; logoLayer.border = 1.0; logoLayer.position = CGPointMake(160, 180); logoLayer.contents = (id)image.CGImage;
  • 11. Layer Geometry X • bounds • position • transform Y • anchorPoint anchorPoint • frame bounds position
  • 13. Implicit Animations • Almost all CALayer properties are animatable • Property changes trigger implicit animations • Animation duration over 1/4 second • Uses linear animation curve by default • Multiple changes batched into transaction megaManLayer.position = CGPointMake(200, 100);
  • 14. Explicit Animations • Core Animation provides support for explicit animations • Provides more fine-grained control • Primary classes • CABasicAnimation • CAKeyframeAnimation • CAAnimationGroup
  • 15. Basic Animations CABasicAnimation • Create an animation for a keyPath: • @"position" • @"transform.rotation.z" • @"backgroundColor" • Set its toValue and fromValue properties • Add the animation to the layer to animate
  • 16. CABasicAnimation Example CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"]; animation.fromValue = [NSNumber numberWithFloat:1.0]; animation.toValue = [NSNumber numberWithFloat:0.0]; animation.duration = 1.0; [layer addAnimation:animation forKey:@"animateOpacity"];
  • 17. CABasicAnimation Example CABasicAnimation *animation = Gotcha Alert [CABasicAnimation animationWithKeyPath:@"opacity"]; animation.fromValue = [NSNumber numberWithFloat:1.0]; animation.toValue = [NSNumber numberWithFloat:0.0]; animation.duration = 1.0; layer.opacity = 0.0; Update the model to make it stick [layer addAnimation:animation forKey:@"animateOpacity"];
  • 18. Key Frame Animations CAKeyframeAnimation • Provides more advanced animation behavior • Animate across collection of "key frames" • path (CGPathRef) • values (NSArray of values) • Can define timing of each point or value
  • 19. CAKeyframeAnimation Example CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; animation.path = path; // CGPathRef animation.duration = 2.0f; animation.rotationMode = kCAAnimationRotateAuto; [layer addAnimation:animation forKey:@"animatePosition"];
  • 20. Transforming Layers CATransform3D • Layer transformations with CATransform3D • Similar to CGAffineTransform • Transforms can be performed in X,Y, and Z • Transformations created using: • CATransform3DScale() • CATransform3DRotate() • CATransform3DTranslate() • Can set transform and sublayerTransform
  • 21. CATransform3D Example CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; // Animate 2, counter-clockwise 360 degree rotations CGFloat radians = (2 * M_PI) * -2 animation.toValue = [NSNumber numberWithFloat:radians]; animation.duration = 0.75f; [layer addAnimation:animation forKey:@"animateRotation"];
  • 24. UIView Animations • UIView is a lightweight wrapper over CALayer • Every view has an associated CALayer • Override layerClass class method to change instance • UIKit provides support for common animations • Behavior for free with animated:YES • Low cost view transitions • Uses Core Animation under the hood
  • 25. Core Animation and UIKit • View and Layers are complimentary • CA layers provide no event handling • Manual hit testing • No gesture recognizers • Layers provides more animatable properties • Layers provide additional capabilities • cornerRadius, border, shadows • Need Core Animation to move beyond stock animations
  • 26. Animating Views in iOS < 4.0 [UIView beginAnimations:@"fadeMe" context:NULL]; [UIView setAnimationDuration:1.0]; self.megaManView.alpha = 0.0f; [UIView commitAnimations];
  • 27. View Animations in iOS 4 [UIView animateWithDuration:1.0 animations:^{ self.megaManView.alpha = 0.0f; }];
  • 28. Blocks-based Animation API animateWithDuration: animations: Simple Animations animateWithDuration: animations: Simple Animations with completion: completion callback animateWithDuration: delay: More complex with options: animations: customizable options completion:
  • 29. Blocks-based Animation API animateWithDuration: animations: Simple Animations animateWithDuration: animations: Simple Animations with completion: completion callback animateWithDuration: delay: More complex with options: animations: customizable options completion:
  • 30. Animation Options UIViewAnimationOption • Bit mask to specify animation behavior • Repeating and autoreverse behavior • Enabling user interaction • Blocks-based API defaults to NO • Specifying animation curves • Beginning an animation from current state • Property inheritance
  • 31. View Transitions • UIView provides common animated transitions • Reveals, Slides, Flips, Curls, etc. • Transitions performed using: • transitionWithView: • transitionFromView:toView: • Transitions behavior customized with animation options mask
  • 33. Summary • CA provides powerful, easy to use API • Lightweight • Hardware accelerated • Robust animations without OpenGL • UIView and Core Animation • UIKit provides support for common animations • Can use Core Animation directly where more power and flexibility is needed