SlideShare a Scribd company logo
1 of 47
Core Graphic
      &
Core Animation

    Andreas Blick
    @aquarioverde
Agenda
  •       Introduction / Overview

  •       Core Graphics / Quartz2D

      •     Explanation

      •     Demo

  •       Core Animation

      •     Explanation

      •     Demo

CG & CA              19/11/2011 - Barcelona Develper Conference   @aquarioverde
Why?
  •       User Experience

      •     Extra polish

      •     Visual Feedback

  •       More human, more natural, real life

  •       User guiding

  •       Usability


CG & CA               19/11/2011 - Barcelona Develper Conference   @aquarioverde
Quartz2D

  •       Quartz2D forms part of the Core Graphics
          Framework

  •       They are often interchanged synonymously

  •       2D text and and graphics rendering library

  •       C based API



CG & CA              19/11/2011 - Barcelona Develper Conference   @aquarioverde
Architecture
                            UIKit


                    Core Animation


          Open GL                     Core Graphics


                             GPU


CG & CA     19/11/2011 - Barcelona Develper Conference   @aquarioverde
drawRect
  • To draw we need a graphics context
  • Lazy drawing
              - (void)drawRect:(CGRect)rect
              {
                  // Drawing code
              }


   [self setNeedsDisplay];
   [self setNeedsDisplayInRect:(CGRect)invalidRect;



CG & CA          19/11/2011 - Barcelona Develper Conference   @aquarioverde
Demo 1
                           Draw simple line

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGRect currentBounds = self.bounds;

    CGContextSetLineWidth(context, 3.0f);
    CGContextSetStrokeColorWithColor(context,
       [UIColor blueColor].CGColor);

    CGContextMoveToPoint(context, 0.0f, CGRectGetMidY(currentBounds));
    CGContextAddLineToPoint(context, CGRectGetMaxX(currentBounds),
       CGRectGetMidY(currentBounds));

    CGContextDrawPath(context, kCGPathStroke);
}



CG & CA               19/11/2011 - Barcelona Develper Conference   @aquarioverde
Coordinate Sytem
            UIView                                                      CG
(0,0)                                      x             y
            frame: (50,50, 75, 75)
            bounds: (0, 0, 75, 75)




  y                                               (0,0)                                  x
  CG & CA                  19/11/2011 - Barcelona Develper Conference    @aquarioverde
Drawing
  •       Drawing is procedural!

  •       Everything goes in order

  •       Use grahpic states

  •       CGPath vs CGContext


                   CGContextSaveGState(context);
                   CGContextRestoreGState(context);




CG & CA              19/11/2011 - Barcelona Develper Conference   @aquarioverde
Paths
  •       Defined shapes

      •     Lines

      •     Arcs

      •     (Bezier) Curves

      •     Rectangles

  •       Also used for

      •     Clipping

CG & CA                19/11/2011 - Barcelona Develper Conference   @aquarioverde
Drawing
  • Drawing modes:
   • Stroke, fill, ...
  • Line cap and join styles
   • Round, bevel
      CGContextBeginPath(context);
     ...
      CGContextClosePath(context);
      CGContextDrawPath(context, kCGPathStroke);


CG & CA           19/11/2011 - Barcelona Develper Conference   @aquarioverde
Context Types

  • CGPDFContextCreate
   • CGContextRelease
  • UIGraphicsBeginImageContext
   • UIImagePNGRepresentation

CG & CA      19/11/2011 - Barcelona Develper Conference   @aquarioverde
Demo 2
                    Draw a text with shadow



- (void)drawTextInRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetShadowWithColor(context, CGSizeMake(5.0, 2.0), 3.0,
       [UIColor grayColor].CGColor);

    [super drawTextInRect:rect];
}




CG & CA               19/11/2011 - Barcelona Develper Conference   @aquarioverde
Transformations

  •       Scaling

  •       Rotation

  •       Translation



            CGContextTranslateCTM(context, 0.0f, self.frame.size.height);
            CGContextScaleCTM(context, 1.0f, -1.0f);


CG & CA                  19/11/2011 - Barcelona Develper Conference   @aquarioverde
Text Drawing
  •       Using Quartz

      •     Fast but restricted to MacRoman character set

  •       UIKit Alternative

      •     Very slow

      •     Uses UIKit coordinate system!

           [myString drawAtPoint:CGPointMake(0.0, 0.0)
             withFont:[UIFont systemFontOfSize:12.0]];


CG & CA              19/11/2011 - Barcelona Develper Conference   @aquarioverde
Demo 3
                     Draw a gradient button

CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB();

CGGradientRef buttonGradient = CGGradientCreateWithColorComponents
   (rgbColorSpace, components, locations, nrOfLocations);

CGRect buttonBounds = self.bounds;
CGPoint gradientStart = CGPointMake(CGRectGetMidX(buttonBounds), 0.0f);
CGPoint gradientEnd = CGPointMake(CGRectGetMidX(buttonBounds),
   CGRectGetMidY(buttonBounds));

CGContextDrawLinearGradient(context, buttonGradient, gradientStart,
   gradientEnd, 0);




CG & CA               19/11/2011 - Barcelona Develper Conference   @aquarioverde
Pixel aligned drawing
  •       User space vs device space

      •     Drawing uses points instead of pixels!

      •     Float coordinates

  •       Uses half pixel boundary

      •     Path inbetween pixels

      •     Offset half a pixel if necessary


CG & CA               19/11/2011 - Barcelona Develper Conference   @aquarioverde
Pixel aligned drawing




CG & CA   19/11/2011 - Barcelona Develper Conference   @aquarioverde
Pixel aligned drawing
          (2.0, 0.0)




CG & CA                19/11/2011 - Barcelona Develper Conference   @aquarioverde
Pixel aligned drawing
          (2.0, 0.0)




CG & CA                19/11/2011 - Barcelona Develper Conference   @aquarioverde
Pixel aligned drawing
          (2.0, 0.0)




CG & CA                19/11/2011 - Barcelona Develper Conference   @aquarioverde
Pixel aligned drawing
          (2.0, 0.0)   (4.5, 0.0)




CG & CA                       19/11/2011 - Barcelona Develper Conference   @aquarioverde
Pixel aligned drawing
          (2.0, 0.0)   (4.5, 0.0)




CG & CA                       19/11/2011 - Barcelona Develper Conference   @aquarioverde
Pixel aligned drawing
          (2.0, 0.0)   (4.5, 0.0)




CG & CA                       19/11/2011 - Barcelona Develper Conference   @aquarioverde
Pixel aligned drawing
          (2.0, 0.0)   (4.5, 0.0)




CG & CA                       19/11/2011 - Barcelona Develper Conference   @aquarioverde
Pixel aligned drawing
          (2.0, 0.0)   (4.5, 0.0)




                                                                  Fill




CG & CA                       19/11/2011 - Barcelona Develper Conference   @aquarioverde
References
  • Quartz2D Programming Guide
  • Core Graphics Framework Reference
  • Cocoa Drawing Guide
  • Drawing and Printing Guide for iOS
  • UIKit Function Reference
  • NSString (UIKit Additions)
CG & CA      19/11/2011 - Barcelona Develper Conference   @aquarioverde
Core Animation

  •       Objective C framework for graphics rendering,
          proyection and animation

  •       Behind the scenes of any UIView

  •       Executed on GPU

  •       Done in background thread



CG & CA              19/11/2011 - Barcelona Develper Conference   @aquarioverde
UIView Animation

  • Core Animation behind the scenes
  • Handles all the math
  • Animatable properties:
   • center, frame, bounds, color, opacity, ...
  • Blocks vs. pre iOS4
CG & CA        19/11/2011 - Barcelona Develper Conference   @aquarioverde
Pre iOS 4

  •       Animate everything that is between begin and
          commit methods

  •       Duration, animation curve

  •       Repeat count, repeat autoreverse

  •       Delegate to chain animations



CG & CA              19/11/2011 - Barcelona Develper Conference   @aquarioverde
Demo 4
                  Pre iOS 4 about view appear


[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

self.aboutView.alpha = 1.0;
self.aboutView.frame = finalFrame;

[UIView commitAnimations];




CG & CA               19/11/2011 - Barcelona Develper Conference   @aquarioverde
Blocks


  •       One line of code (even though a long line)

  •       No delegates/callbacks necessary

  •       Synchronized




CG & CA              19/11/2011 - Barcelona Develper Conference   @aquarioverde
UIView Transitions

  •       Animations to execute when switching views

  •       Always need a container view

  •       They have a meaning: HIG

  •       Differ from iPad to iPhone

  •       ModalViewController



CG & CA              19/11/2011 - Barcelona Develper Conference   @aquarioverde
Demo 6
                         iPad CurlUp Block



[UIView transitionFromView:(self.aboutView)
       toView:(self.venueView)
       duration:1.0
       options:(UIViewAnimationOptionTransitionCurlDown |
       UIViewAnimationOptionShowHideTransitionViews)
       completion:^(BOOL finished) {
       }];




CG & CA               19/11/2011 - Barcelona Develper Conference   @aquarioverde
CALayer Animations

  • Every UIView is backed by a CALayer
   • QuartzCore framework
  • No touch support
  • Slightly higher performance on iOS
  • Same on MacOS as on iOS
CG & CA      19/11/2011 - Barcelona Develper Conference   @aquarioverde
Layer geometry
          (0,0)                                               x

                                                                     bounds

          sublayer



                                                              position:
                                                              anchorPoint (0.5, 0.5)


               y
CG & CA          19/11/2011 - Barcelona Develper Conference           @aquarioverde
Layer geometry




CG & CA     19/11/2011 - Barcelona Develper Conference   @aquarioverde
Layer geometry




CG & CA     19/11/2011 - Barcelona Develper Conference   @aquarioverde
Layer geometry




CG & CA     19/11/2011 - Barcelona Develper Conference   @aquarioverde
Layer Types
  •       CAEAGLLayer

  •       CATiledLayer

  •       CAScrollLayer

  •       CAReplicatorLayer

  •       CAShapeLayer

  •       CAGradientLayer


CG & CA             19/11/2011 - Barcelona Develper Conference   @aquarioverde
CALayer
  • Key-value compliant
  • Drawing
   • Don’t subclass
   • Use delegates instead
  • Every layer has a presentation layer
   • Hit testing to get current position
CG & CA       19/11/2011 - Barcelona Develper Conference   @aquarioverde
Implicit Animations
  •       Property changes

  •       Animates automatically

      •     1/4 second

      •     linear

  •       Exception: UIView layer

  •       Animation Transaction

      •     begin, commit

CG & CA              19/11/2011 - Barcelona Develper Conference   @aquarioverde
Explicit Animation
  •       CABasicAnimation

  •       CAKeyframeAnimation

      •     Define animation points and timing

      •     Keypath animation

           •   Animate a layer along a drawn path

  •       CAAnimationGroup


CG & CA              19/11/2011 - Barcelona Develper Conference   @aquarioverde
Explicit Animation
  •       CAMediaTimingFunction

  •       Animation chaining: delegate

      •     animationDidStop:finished:

      •     animationDidStart:

  •       CATransform3D

      •     scale, rotate, translate


CG & CA               19/11/2011 - Barcelona Develper Conference   @aquarioverde
Demo 7
                  Custom property animation

CABasicAnimation *iconAnimation =
   [CABasicAnimation animationWithKeyPath:@"position"];

iconAnimation.delegate = self;
iconAnimation.duration = 2.0;
iconAnimation.timingFunction = [CAMediaTimingFunction functionWithName:
   kCAMediaTimingFunctionEaseInEaseOut];

iconAnimation.removedOnCompletion = NO;
iconAnimation.fillMode = kCAFillModeForwards;

iconAnimation.toValue = [NSValue valueWithCGPoint:topIcon.layer.position];

[theAboutIcon.layer addAnimation:iconAnimation forKey:@"moveBelow"];




CG & CA               19/11/2011 - Barcelona Develper Conference   @aquarioverde
References

  • Core Animation Programming Guide
  • Animation Basics
  • UIView Programming Guide - Animations

CG & CA      19/11/2011 - Barcelona Develper Conference   @aquarioverde
Thank You!


 @aquarioverde

More Related Content

What's hot

Low-level Shader Optimization for Next-Gen and DX11 by Emil Persson
Low-level Shader Optimization for Next-Gen and DX11 by Emil PerssonLow-level Shader Optimization for Next-Gen and DX11 by Emil Persson
Low-level Shader Optimization for Next-Gen and DX11 by Emil PerssonAMD Developer Central
 
HKG18-411 - Introduction to OpenAMP which is an open source solution for hete...
HKG18-411 - Introduction to OpenAMP which is an open source solution for hete...HKG18-411 - Introduction to OpenAMP which is an open source solution for hete...
HKG18-411 - Introduction to OpenAMP which is an open source solution for hete...Linaro
 
Vim cheat-sheet-en
Vim cheat-sheet-enVim cheat-sheet-en
Vim cheat-sheet-engetdownload
 
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14AMD Developer Central
 
OpenGL 3.2 and More
OpenGL 3.2 and MoreOpenGL 3.2 and More
OpenGL 3.2 and MoreMark Kilgard
 
Mieszko Zielinski (Epic Games), White Nights 2015
Mieszko Zielinski  (Epic Games), White Nights 2015 Mieszko Zielinski  (Epic Games), White Nights 2015
Mieszko Zielinski (Epic Games), White Nights 2015 White Nights Conference
 
PerfectVIPs Uvm tlm slides format
PerfectVIPs Uvm tlm slides formatPerfectVIPs Uvm tlm slides format
PerfectVIPs Uvm tlm slides formatAkash Mohanty
 
Top 8 wintel administrator resume samples
Top 8 wintel administrator resume samplesTop 8 wintel administrator resume samples
Top 8 wintel administrator resume samplesglassybravo
 
Reconnaissance of Virtio: What’s new and how it’s all connected?
Reconnaissance of Virtio: What’s new and how it’s all connected?Reconnaissance of Virtio: What’s new and how it’s all connected?
Reconnaissance of Virtio: What’s new and how it’s all connected?Samsung Open Source Group
 
Kernel Process Management
Kernel Process ManagementKernel Process Management
Kernel Process Managementpradeep_tewani
 
LAS16-TR06: Remoteproc & rpmsg development
LAS16-TR06: Remoteproc & rpmsg developmentLAS16-TR06: Remoteproc & rpmsg development
LAS16-TR06: Remoteproc & rpmsg developmentLinaro
 
from Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Worksfrom Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu WorksZhen Wei
 
HSA Kernel Code (KFD v0.6)
HSA Kernel Code (KFD v0.6)HSA Kernel Code (KFD v0.6)
HSA Kernel Code (KFD v0.6)Hann Yu-Ju Huang
 
How to create a high quality, fast texture compressor using ISPC
How to create a high quality, fast texture compressor using ISPC How to create a high quality, fast texture compressor using ISPC
How to create a high quality, fast texture compressor using ISPC Gael Hofemeier
 

What's hot (20)

Low-level Shader Optimization for Next-Gen and DX11 by Emil Persson
Low-level Shader Optimization for Next-Gen and DX11 by Emil PerssonLow-level Shader Optimization for Next-Gen and DX11 by Emil Persson
Low-level Shader Optimization for Next-Gen and DX11 by Emil Persson
 
HKG18-411 - Introduction to OpenAMP which is an open source solution for hete...
HKG18-411 - Introduction to OpenAMP which is an open source solution for hete...HKG18-411 - Introduction to OpenAMP which is an open source solution for hete...
HKG18-411 - Introduction to OpenAMP which is an open source solution for hete...
 
Spi drivers
Spi driversSpi drivers
Spi drivers
 
Vim cheat-sheet-en
Vim cheat-sheet-enVim cheat-sheet-en
Vim cheat-sheet-en
 
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
 
OpenGL 3.2 and More
OpenGL 3.2 and MoreOpenGL 3.2 and More
OpenGL 3.2 and More
 
Mieszko Zielinski (Epic Games), White Nights 2015
Mieszko Zielinski  (Epic Games), White Nights 2015 Mieszko Zielinski  (Epic Games), White Nights 2015
Mieszko Zielinski (Epic Games), White Nights 2015
 
PerfectVIPs Uvm tlm slides format
PerfectVIPs Uvm tlm slides formatPerfectVIPs Uvm tlm slides format
PerfectVIPs Uvm tlm slides format
 
BusyBox for Embedded Linux
BusyBox for Embedded LinuxBusyBox for Embedded Linux
BusyBox for Embedded Linux
 
Top 8 wintel administrator resume samples
Top 8 wintel administrator resume samplesTop 8 wintel administrator resume samples
Top 8 wintel administrator resume samples
 
Reconnaissance of Virtio: What’s new and how it’s all connected?
Reconnaissance of Virtio: What’s new and how it’s all connected?Reconnaissance of Virtio: What’s new and how it’s all connected?
Reconnaissance of Virtio: What’s new and how it’s all connected?
 
I2C Drivers
I2C DriversI2C Drivers
I2C Drivers
 
Kernel Process Management
Kernel Process ManagementKernel Process Management
Kernel Process Management
 
Toolchain
ToolchainToolchain
Toolchain
 
LAS16-TR06: Remoteproc & rpmsg development
LAS16-TR06: Remoteproc & rpmsg developmentLAS16-TR06: Remoteproc & rpmsg development
LAS16-TR06: Remoteproc & rpmsg development
 
Audio Drivers
Audio DriversAudio Drivers
Audio Drivers
 
from Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Worksfrom Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Works
 
Building Paragon in UE4
Building Paragon in UE4Building Paragon in UE4
Building Paragon in UE4
 
HSA Kernel Code (KFD v0.6)
HSA Kernel Code (KFD v0.6)HSA Kernel Code (KFD v0.6)
HSA Kernel Code (KFD v0.6)
 
How to create a high quality, fast texture compressor using ISPC
How to create a high quality, fast texture compressor using ISPC How to create a high quality, fast texture compressor using ISPC
How to create a high quality, fast texture compressor using ISPC
 

Viewers also liked

Core Animation
Core AnimationCore Animation
Core AnimationBob McCune
 
Drawing with Quartz on iOS
Drawing with Quartz on iOSDrawing with Quartz on iOS
Drawing with Quartz on iOSBob McCune
 
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
 
Starting Core Animation
Starting Core AnimationStarting Core Animation
Starting Core AnimationJohn Wilker
 
Creating Container View Controllers
Creating Container View ControllersCreating Container View Controllers
Creating Container View ControllersBob McCune
 
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
 
Basketball
BasketballBasketball
Basketballnycdoe
 
Jocelyn power point
Jocelyn power pointJocelyn power point
Jocelyn power pointnycdoe
 
Rocking slideshow
Rocking slideshowRocking slideshow
Rocking slideshownycdoe
 
احترف صيانة الكمبيوتر
احترف صيانة الكمبيوتراحترف صيانة الكمبيوتر
احترف صيانة الكمبيوترtitifcom
 
If then vb2010
If then vb2010If then vb2010
If then vb2010Spy Seat
 
الإنترنت في خدمة الباحثين
الإنترنت في خدمة الباحثينالإنترنت في خدمة الباحثين
الإنترنت في خدمة الباحثينMostafa Gawdat
 
Master Video with AV Foundation
Master Video with AV FoundationMaster Video with AV Foundation
Master Video with AV FoundationBob McCune
 
تصميم مواقع
تصميم مواقع تصميم مواقع
تصميم مواقع Shooq Alrabeh
 
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
 
20 iOS developer interview questions
20 iOS developer interview questions20 iOS developer interview questions
20 iOS developer interview questionsArc & Codementor
 
iOS Developer Interview Questions
iOS Developer Interview QuestionsiOS Developer Interview Questions
iOS Developer Interview QuestionsClark Davidson
 

Viewers also liked (20)

Core Animation
Core AnimationCore Animation
Core Animation
 
Graphics Libraries
Graphics LibrariesGraphics Libraries
Graphics Libraries
 
Drawing with Quartz on iOS
Drawing with Quartz on iOSDrawing with Quartz on iOS
Drawing with Quartz on iOS
 
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
 
Starting Core Animation
Starting Core AnimationStarting Core Animation
Starting Core Animation
 
Creating Container View Controllers
Creating Container View ControllersCreating Container View Controllers
Creating Container View Controllers
 
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
 
Basketball
BasketballBasketball
Basketball
 
Jocelyn power point
Jocelyn power pointJocelyn power point
Jocelyn power point
 
Rocking slideshow
Rocking slideshowRocking slideshow
Rocking slideshow
 
احترف صيانة الكمبيوتر
احترف صيانة الكمبيوتراحترف صيانة الكمبيوتر
احترف صيانة الكمبيوتر
 
If then vb2010
If then vb2010If then vb2010
If then vb2010
 
الإنترنت في خدمة الباحثين
الإنترنت في خدمة الباحثينالإنترنت في خدمة الباحثين
الإنترنت في خدمة الباحثين
 
Master Video with AV Foundation
Master Video with AV FoundationMaster Video with AV Foundation
Master Video with AV Foundation
 
تصميم مواقع
تصميم مواقع تصميم مواقع
تصميم مواقع
 
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
 
Animation in iOS
Animation in iOSAnimation in iOS
Animation in iOS
 
20 iOS developer interview questions
20 iOS developer interview questions20 iOS developer interview questions
20 iOS developer interview questions
 
iOS Developer Interview Questions
iOS Developer Interview QuestionsiOS Developer Interview Questions
iOS Developer Interview Questions
 

Similar to Core Graphics & Core Animation

K8s is not for App Developers
K8s is not for App DevelopersK8s is not for App Developers
K8s is not for App DevelopersQAware GmbH
 
Half-Life_Alyx_Locomotion_Slides.pdf
Half-Life_Alyx_Locomotion_Slides.pdfHalf-Life_Alyx_Locomotion_Slides.pdf
Half-Life_Alyx_Locomotion_Slides.pdfLiJimmy1
 
用 IBDesignable 作 UI
用 IBDesignable 作 UI用 IBDesignable 作 UI
用 IBDesignable 作 UITsungyu Yu
 
PDE2011 pythonOCC project status and plans
PDE2011 pythonOCC project status and plansPDE2011 pythonOCC project status and plans
PDE2011 pythonOCC project status and plansThomas Paviot
 
Introduction of openGL
Introduction  of openGLIntroduction  of openGL
Introduction of openGLGary Yeh
 
XebiCon'18 - Passage à l'échelle de mes applications Kafka-Streams
XebiCon'18 - Passage à l'échelle de mes applications Kafka-StreamsXebiCon'18 - Passage à l'échelle de mes applications Kafka-Streams
XebiCon'18 - Passage à l'échelle de mes applications Kafka-StreamsPublicis Sapient Engineering
 
The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...
The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...
The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...Docker, Inc.
 
Dockercon EU 2014
Dockercon EU 2014Dockercon EU 2014
Dockercon EU 2014Rafe Colton
 
Rotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billyRotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billynimbleltd
 
MAYA HTT NX ST CAD-CAE Workflows
MAYA HTT NX ST CAD-CAE WorkflowsMAYA HTT NX ST CAD-CAE Workflows
MAYA HTT NX ST CAD-CAE WorkflowsDora Smith
 
Maya HTT NX CAD Assoc Fluid Domains
Maya HTT NX CAD Assoc Fluid DomainsMaya HTT NX CAD Assoc Fluid Domains
Maya HTT NX CAD Assoc Fluid DomainsDora Smith
 
Drools, jBPM OptaPlanner presentation
Drools, jBPM OptaPlanner presentationDrools, jBPM OptaPlanner presentation
Drools, jBPM OptaPlanner presentationMark Proctor
 
Latest Developments of Scalable Vector Graphics (SVG) 2, With a Focus on Stre...
Latest Developments of Scalable Vector Graphics (SVG) 2, With a Focus on Stre...Latest Developments of Scalable Vector Graphics (SVG) 2, With a Focus on Stre...
Latest Developments of Scalable Vector Graphics (SVG) 2, With a Focus on Stre...Förderverein Technische Fakultät
 
Cairo Graphics Kit
Cairo Graphics KitCairo Graphics Kit
Cairo Graphics KitESUG
 
SnapyX
SnapyXSnapyX
SnapyXekino
 
Microservices architecture: practical aspects
Microservices architecture: practical aspectsMicroservices architecture: practical aspects
Microservices architecture: practical aspectsAntonio Sagliocco
 
The Android graphics path, in depth
The Android graphics path, in depthThe Android graphics path, in depth
The Android graphics path, in depthChris Simmonds
 
The Next Generation Eclipse Graphical Editing Framework
The Next Generation Eclipse Graphical Editing FrameworkThe Next Generation Eclipse Graphical Editing Framework
The Next Generation Eclipse Graphical Editing FrameworkAlexander Nyßen
 

Similar to Core Graphics & Core Animation (20)

K8s is not for App Developers
K8s is not for App DevelopersK8s is not for App Developers
K8s is not for App Developers
 
Half-Life_Alyx_Locomotion_Slides.pdf
Half-Life_Alyx_Locomotion_Slides.pdfHalf-Life_Alyx_Locomotion_Slides.pdf
Half-Life_Alyx_Locomotion_Slides.pdf
 
用 IBDesignable 作 UI
用 IBDesignable 作 UI用 IBDesignable 作 UI
用 IBDesignable 作 UI
 
PDE2011 pythonOCC project status and plans
PDE2011 pythonOCC project status and plansPDE2011 pythonOCC project status and plans
PDE2011 pythonOCC project status and plans
 
Introduction of openGL
Introduction  of openGLIntroduction  of openGL
Introduction of openGL
 
XebiCon'18 - Passage à l'échelle de mes applications Kafka-Streams
XebiCon'18 - Passage à l'échelle de mes applications Kafka-StreamsXebiCon'18 - Passage à l'échelle de mes applications Kafka-Streams
XebiCon'18 - Passage à l'échelle de mes applications Kafka-Streams
 
The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...
The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...
The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...
 
Dockercon EU 2014
Dockercon EU 2014Dockercon EU 2014
Dockercon EU 2014
 
Rotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billyRotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billy
 
MAYA HTT NX ST CAD-CAE Workflows
MAYA HTT NX ST CAD-CAE WorkflowsMAYA HTT NX ST CAD-CAE Workflows
MAYA HTT NX ST CAD-CAE Workflows
 
Maya HTT NX CAD Assoc Fluid Domains
Maya HTT NX CAD Assoc Fluid DomainsMaya HTT NX CAD Assoc Fluid Domains
Maya HTT NX CAD Assoc Fluid Domains
 
Drools, jBPM OptaPlanner presentation
Drools, jBPM OptaPlanner presentationDrools, jBPM OptaPlanner presentation
Drools, jBPM OptaPlanner presentation
 
Latest Developments of Scalable Vector Graphics (SVG) 2, With a Focus on Stre...
Latest Developments of Scalable Vector Graphics (SVG) 2, With a Focus on Stre...Latest Developments of Scalable Vector Graphics (SVG) 2, With a Focus on Stre...
Latest Developments of Scalable Vector Graphics (SVG) 2, With a Focus on Stre...
 
Cairo Graphics Kit
Cairo Graphics KitCairo Graphics Kit
Cairo Graphics Kit
 
SnapyX
SnapyXSnapyX
SnapyX
 
SnapyX - ParisJS
SnapyX - ParisJSSnapyX - ParisJS
SnapyX - ParisJS
 
Guides To Analyzing WebKit Performance
Guides To Analyzing WebKit PerformanceGuides To Analyzing WebKit Performance
Guides To Analyzing WebKit Performance
 
Microservices architecture: practical aspects
Microservices architecture: practical aspectsMicroservices architecture: practical aspects
Microservices architecture: practical aspects
 
The Android graphics path, in depth
The Android graphics path, in depthThe Android graphics path, in depth
The Android graphics path, in depth
 
The Next Generation Eclipse Graphical Editing Framework
The Next Generation Eclipse Graphical Editing FrameworkThe Next Generation Eclipse Graphical Editing Framework
The Next Generation Eclipse Graphical Editing Framework
 

Recently uploaded

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
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
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
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
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
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
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
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
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 

Recently uploaded (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
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...
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 

Core Graphics & Core Animation

  • 1. Core Graphic & Core Animation Andreas Blick @aquarioverde
  • 2. Agenda • Introduction / Overview • Core Graphics / Quartz2D • Explanation • Demo • Core Animation • Explanation • Demo CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 3. Why? • User Experience • Extra polish • Visual Feedback • More human, more natural, real life • User guiding • Usability CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 4. Quartz2D • Quartz2D forms part of the Core Graphics Framework • They are often interchanged synonymously • 2D text and and graphics rendering library • C based API CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 5. Architecture UIKit Core Animation Open GL Core Graphics GPU CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 6. drawRect • To draw we need a graphics context • Lazy drawing - (void)drawRect:(CGRect)rect { // Drawing code } [self setNeedsDisplay]; [self setNeedsDisplayInRect:(CGRect)invalidRect; CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 7. Demo 1 Draw simple line - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGRect currentBounds = self.bounds; CGContextSetLineWidth(context, 3.0f); CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); CGContextMoveToPoint(context, 0.0f, CGRectGetMidY(currentBounds)); CGContextAddLineToPoint(context, CGRectGetMaxX(currentBounds), CGRectGetMidY(currentBounds)); CGContextDrawPath(context, kCGPathStroke); } CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 8. Coordinate Sytem UIView CG (0,0) x y frame: (50,50, 75, 75) bounds: (0, 0, 75, 75) y (0,0) x CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 9. Drawing • Drawing is procedural! • Everything goes in order • Use grahpic states • CGPath vs CGContext CGContextSaveGState(context); CGContextRestoreGState(context); CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 10. Paths • Defined shapes • Lines • Arcs • (Bezier) Curves • Rectangles • Also used for • Clipping CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 11. Drawing • Drawing modes: • Stroke, fill, ... • Line cap and join styles • Round, bevel CGContextBeginPath(context); ... CGContextClosePath(context); CGContextDrawPath(context, kCGPathStroke); CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 12. Context Types • CGPDFContextCreate • CGContextRelease • UIGraphicsBeginImageContext • UIImagePNGRepresentation CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 13. Demo 2 Draw a text with shadow - (void)drawTextInRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetShadowWithColor(context, CGSizeMake(5.0, 2.0), 3.0, [UIColor grayColor].CGColor); [super drawTextInRect:rect]; } CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 14. Transformations • Scaling • Rotation • Translation CGContextTranslateCTM(context, 0.0f, self.frame.size.height); CGContextScaleCTM(context, 1.0f, -1.0f); CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 15. Text Drawing • Using Quartz • Fast but restricted to MacRoman character set • UIKit Alternative • Very slow • Uses UIKit coordinate system! [myString drawAtPoint:CGPointMake(0.0, 0.0) withFont:[UIFont systemFontOfSize:12.0]]; CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 16. Demo 3 Draw a gradient button CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB(); CGGradientRef buttonGradient = CGGradientCreateWithColorComponents (rgbColorSpace, components, locations, nrOfLocations); CGRect buttonBounds = self.bounds; CGPoint gradientStart = CGPointMake(CGRectGetMidX(buttonBounds), 0.0f); CGPoint gradientEnd = CGPointMake(CGRectGetMidX(buttonBounds), CGRectGetMidY(buttonBounds)); CGContextDrawLinearGradient(context, buttonGradient, gradientStart, gradientEnd, 0); CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 17. Pixel aligned drawing • User space vs device space • Drawing uses points instead of pixels! • Float coordinates • Uses half pixel boundary • Path inbetween pixels • Offset half a pixel if necessary CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 18. Pixel aligned drawing CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 19. Pixel aligned drawing (2.0, 0.0) CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 20. Pixel aligned drawing (2.0, 0.0) CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 21. Pixel aligned drawing (2.0, 0.0) CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 22. Pixel aligned drawing (2.0, 0.0) (4.5, 0.0) CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 23. Pixel aligned drawing (2.0, 0.0) (4.5, 0.0) CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 24. Pixel aligned drawing (2.0, 0.0) (4.5, 0.0) CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 25. Pixel aligned drawing (2.0, 0.0) (4.5, 0.0) CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 26. Pixel aligned drawing (2.0, 0.0) (4.5, 0.0) Fill CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 27. References • Quartz2D Programming Guide • Core Graphics Framework Reference • Cocoa Drawing Guide • Drawing and Printing Guide for iOS • UIKit Function Reference • NSString (UIKit Additions) CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 28. Core Animation • Objective C framework for graphics rendering, proyection and animation • Behind the scenes of any UIView • Executed on GPU • Done in background thread CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 29. UIView Animation • Core Animation behind the scenes • Handles all the math • Animatable properties: • center, frame, bounds, color, opacity, ... • Blocks vs. pre iOS4 CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 30. Pre iOS 4 • Animate everything that is between begin and commit methods • Duration, animation curve • Repeat count, repeat autoreverse • Delegate to chain animations CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 31. Demo 4 Pre iOS 4 about view appear [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:2.0]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; self.aboutView.alpha = 1.0; self.aboutView.frame = finalFrame; [UIView commitAnimations]; CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 32. Blocks • One line of code (even though a long line) • No delegates/callbacks necessary • Synchronized CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 33. UIView Transitions • Animations to execute when switching views • Always need a container view • They have a meaning: HIG • Differ from iPad to iPhone • ModalViewController CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 34. Demo 6 iPad CurlUp Block [UIView transitionFromView:(self.aboutView) toView:(self.venueView) duration:1.0 options:(UIViewAnimationOptionTransitionCurlDown | UIViewAnimationOptionShowHideTransitionViews) completion:^(BOOL finished) { }]; CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 35. CALayer Animations • Every UIView is backed by a CALayer • QuartzCore framework • No touch support • Slightly higher performance on iOS • Same on MacOS as on iOS CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 36. Layer geometry (0,0) x bounds sublayer position: anchorPoint (0.5, 0.5) y CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 37. Layer geometry CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 38. Layer geometry CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 39. Layer geometry CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 40. Layer Types • CAEAGLLayer • CATiledLayer • CAScrollLayer • CAReplicatorLayer • CAShapeLayer • CAGradientLayer CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 41. CALayer • Key-value compliant • Drawing • Don’t subclass • Use delegates instead • Every layer has a presentation layer • Hit testing to get current position CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 42. Implicit Animations • Property changes • Animates automatically • 1/4 second • linear • Exception: UIView layer • Animation Transaction • begin, commit CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 43. Explicit Animation • CABasicAnimation • CAKeyframeAnimation • Define animation points and timing • Keypath animation • Animate a layer along a drawn path • CAAnimationGroup CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 44. Explicit Animation • CAMediaTimingFunction • Animation chaining: delegate • animationDidStop:finished: • animationDidStart: • CATransform3D • scale, rotate, translate CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 45. Demo 7 Custom property animation CABasicAnimation *iconAnimation = [CABasicAnimation animationWithKeyPath:@"position"]; iconAnimation.delegate = self; iconAnimation.duration = 2.0; iconAnimation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut]; iconAnimation.removedOnCompletion = NO; iconAnimation.fillMode = kCAFillModeForwards; iconAnimation.toValue = [NSValue valueWithCGPoint:topIcon.layer.position]; [theAboutIcon.layer addAnimation:iconAnimation forKey:@"moveBelow"]; CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde
  • 46. References • Core Animation Programming Guide • Animation Basics • UIView Programming Guide - Animations CG & CA 19/11/2011 - Barcelona Develper Conference @aquarioverde

Editor's Notes

  1. \n
  2. \n
  3. draw custom user elements\nbeautiful details\nnot just cool effects\nguides the eye\neasy to use\n\n
  4. C based API: needs more coding -> create proper library\nonce you understand the basics its pretty easy\na lot of copy and paste ;-)\n
  5. \n
  6. graphics context: canvas on which we do our 2D drawing\nthe only place where we can get this context is in our drawRect method\ncontext is set up automatically!\ncalled by the system when needed\n\nsetNeedsDisplayInRect:(CGRect)invalidRect\n\n
  7. there’s different context: Bitmap, PDF, Printer ...\nContext, Path, Color, Font, Transformation, ...\nUIColor can be easily converted to CGColor\nUIColor is not the best solution. one should cache colors\nCGXXX helper methods\npainter’s model\n
  8. coordinate spaces simplify the drawing code required to create complex interfaces\nthe window represents the base coordinate system\ntransforms convert coordinate systems\nCocoa and Quartz coordinate systems are the same\ndifferent coordinate systems UI & CG\ncoordinate space for CG is flipped\nbounds vs frame\n
  9. one can create path using CGPath or CGContext. CGContext is “one-time”, while CGPath saves the path.\nGraphic states are implemented as a stack. I can push and pop as many as I need.\n
  10. first define the path then draw it!\npath’ can also be used for other operations, e.g. clipping\n
  11. \n
  12. The important part when using contexts that are created is that I have to release them!!!\nimage context can be used for cached and repeated drawing\n
  13. we use “drawTextInRect” because it handles the actual text drawing (color, spacing, ..)\nwe could do it in “drawRect” but then would have to draw the text ourselves\nparams: context, offset size, blur, color\n
  14. use translation for flipping coordinate space\nCTM: current transformation matrix\n
  15. no Unicode\n
  16. linear gradients and radial gradients\ncan be used for glossy effects\n
  17. vector based drawing model to scale nicely onto the actual pixels of the device\nuser space vs device space \npoints in the user base might not correspond to pixels on the device!\nyou don’t have to care about the device space unless for adjusting anti-aliasing\nscale factor\n\n
  18. vector based drawing model to scale nicely onto the actual pixels of the device\nuser space vs device space \npoints in the user base might not correspond to pixels on the device!\nyou don’t have to care about the device space unless for adjusting anti-aliasing\nscale factor\n\n
  19. vector based drawing model to scale nicely onto the actual pixels of the device\nuser space vs device space \npoints in the user base might not correspond to pixels on the device!\nyou don’t have to care about the device space unless for adjusting anti-aliasing\nscale factor\n\n
  20. vector based drawing model to scale nicely onto the actual pixels of the device\nuser space vs device space \npoints in the user base might not correspond to pixels on the device!\nyou don’t have to care about the device space unless for adjusting anti-aliasing\nscale factor\n\n
  21. vector based drawing model to scale nicely onto the actual pixels of the device\nuser space vs device space \npoints in the user base might not correspond to pixels on the device!\nyou don’t have to care about the device space unless for adjusting anti-aliasing\nscale factor\n\n
  22. vector based drawing model to scale nicely onto the actual pixels of the device\nuser space vs device space \npoints in the user base might not correspond to pixels on the device!\nyou don’t have to care about the device space unless for adjusting anti-aliasing\nscale factor\n\n
  23. vector based drawing model to scale nicely onto the actual pixels of the device\nuser space vs device space \npoints in the user base might not correspond to pixels on the device!\nyou don’t have to care about the device space unless for adjusting anti-aliasing\nscale factor\n\n
  24. vector based drawing model to scale nicely onto the actual pixels of the device\nuser space vs device space \npoints in the user base might not correspond to pixels on the device!\nyou don’t have to care about the device space unless for adjusting anti-aliasing\nscale factor\n\n
  25. vector based drawing model to scale nicely onto the actual pixels of the device\nuser space vs device space \npoints in the user base might not correspond to pixels on the device!\nyou don’t have to care about the device space unless for adjusting anti-aliasing\nscale factor\n\n
  26. vector based drawing model to scale nicely onto the actual pixels of the device\nuser space vs device space \npoints in the user base might not correspond to pixels on the device!\nyou don’t have to care about the device space unless for adjusting anti-aliasing\nscale factor\n\n
  27. \n
  28. \n
  29. Core Animation was designed for the iPhone\nUIKit was designed with Core Animation in mind\n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. Why should we use CALayers instead of UIView Animation\n
  36. frame and bounds as in UIView\nchange of position changes the frame\nif you change the anchor point you’ll move the frame!!\nanchorPoint is the position on which all animation occur\n
  37. frame and bounds as in UIView\nchange of position changes the frame\nif you change the anchor point you’ll move the frame!!\nanchorPoint is the position on which all animation occur\n
  38. frame and bounds as in UIView\nchange of position changes the frame\nif you change the anchor point you’ll move the frame!!\nanchorPoint is the position on which all animation occur\n
  39. CALayer\nCAEAGLLayer \n holds Open GL content\nCATiledLayer \n CALayers have a maximum size\n if you exceed this you can use a CATiledLayer\nCAScrollLayer\n layer for scrolling\n probably never use it because of the powerfulness of UIScrollView\nCAReplicatorLayer\n replicates layers\n use it for particles systems\nCAShapeLayer\n holds a Core Graphics path\n lets you animate between path’ (shapes)\n e.g. used for charts\nCAGradientLayer\n hardware accelerated linear gradients\n fastest way to create a gradient\n \nUIView always returns a CALayer class\nif you want a different kind of layer class you have to overwrite\n\n(Class)layerClass\n{\nreturn [CATiledLayer class];\n}\n\n \n
  40. presentation tree shows what actually is on screen\nlayer.presentationLayer\n
  41. \n
  42. \n
  43. [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];\nanimation.toValue = (2 * M_PI) * -2\n\n
  44. \n
  45. \n
  46. \n