SlideShare a Scribd company logo
CoreAnimation
    Weizhong Yang
     a.k.a zonble
  zonble@gmail.com
   http://zonble.net
https://github.com/zonble/CAShowcase
New BSD License
Why CoreAnimation?

•                            iPad

•     UIView
                    OpenGL
    CoreAnimation
CoreAnimation

•      Mac/iOS framework

•
• UIView              CoreAnimation
  wrapper
CoreAnimation


•   concurrent

•
    …
CoreAnimation

•
•       Mockup


           …

•                   …
CoreAnimation


•   Objective-C

•
Class


• CALayer
• CAAnimation
• CATransaction
• #import <QuartzCore/QuartzCore.h>
CALayer
CALayer
• iOS
 •      UIView               layer [aView
   layer] or aView.layer

• Mac
  • NSView                 setWantsLayer:

•        iOS
CALayer             Interface

•   frame bounds background color

•       layer             layer
      addSublayer

•                             superlayer
CALayer                View

•       responder
    event Click   Touch…

•         property

•
CALayer

• CALayer *aLayer = [CALayer layer];
• aLayer.contents = (id)[UIImage
    imageNamed:@”test.jpg”].CGImage;
•                                  fade in/
    out
CALayer

• aLayer.position = CGPointMake()...
• aLayer.bounds = CGRectMake()...
•
•                   0.25
•       Layer   property

•         CAAnimation

    •      …
CATransaction 1
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue
forKey:kCATransactionDisableActions];
//     CALayer

[CATransaction commit];
//
CATransaction 2
[CATransaction begin];
[CATransaction setValue:[NSNumber
numberWithFloat:2.0] forKey:
kCATransactionAnimationDuration];
//     CALayer

[CATransaction commit];
CATransition…
CATransition *t = [CATransition animation];
t.type = kCATransitionMoveIn
t.subtype = kCATransitionFromRight;
aLayer.contents = (id)[UIImage
imageNamed:@”test.jpg”].CGImage;
[aLayer addAnimation:t forKey:@"Transition"];
//
CATransition


•   Private API flip   cube

•         reject      …
CAAnimation
CAAnimation

• CABasicAnimation
• CAKeyframeAnimation
• CAAnimationGroup
• CATransition …
CABasicAnimation
• [CABasicAnimation
  animationWithKeyPath:...]
 • @”position”
 • @”bounds”
 • @”opacity”
 • @”contents”...
CABasicAnimation
•
    • @”transform.rotation.x”
    • @”transform.rotation.y”
    • @”transform.rotation.z”
    • ...
CABasicAnimation

• fromValue = [NSValue...];
• toValue = [NSValue ...];
• duration = 3.0; //Seconds
• repeatCount = NSUIntegerMax; // Forever
CAKeyframeAnimation
•          fromValue toValue
    CGPathRef
• CAKeyframeAnimation *a
    =[CAKeyframeAnimation
    animationWithKeyPath:@"position"];
• a.path = (CGPathRef)path;
CAAnimationGroup

• CAAnimationGroup *group  =
  [CAAnimationGroup animation];
• group.animations = [NSArray
  arrayWithObjects:anim1, anim2, nil];
CAAnimation


• [aLayer addAnimation:myAnimation
  forKey:@"MyKey"];
fill mode

•                       layer



• animation.fillMode =
    kCAFillModeForwards;
    •                           …
CABasicAnimation *a = [CABasicAnimation
    animationWithKeyPath:@”bounds”];
    a.fromValue = [NSValue valuwWithCGRect:fromRect];
    a.toValue = [NSValue valuwWithCGRect:toRect];
    [aLayer addAnimation:a forKey:@"boundsAnimation"];
    NSLog(@”bounds:%@”, NSStringFromCGRect(aLayer.bounds));

•                         bounds              toValue

•                 layer                         layer    property
Layer
• [aLayer addAnimation:myAnimation1
    forKey:@"MyKey1"];
• [aLayer addAnimation:myAnimation2
    forKey:@"MyKey2"];
•
• [self
    perforeSelector:@selector(runAnimation1)
    withObject:nil afterDelay:1.0]; //

• [self
    perforeSelector:@selector(runAnimation2)
    withObject:nil afterDelay:2.0]; //

•
beginTime
• animation1.beginTime =
    CACurrentMediaTime() + 1.0; //

• animation2.beginTime =
    CACurrentMediaTime() + 2.0; //

•            CAAnimation
                             …
animation

• layer        view

•
  layer   UIView      layer
  view.layer

• app
animation.delegate = self;
[myLayer addAnimation: animation forKey:@”key”];
...
- (void)animationDidStop:(CAAnimation
*)theAnimation finished:(BOOL)flag {
// Fire another animation
}
//
delegate
animation.delegate = self;
animation.removedOnCompletion = NO;
[myLayer addAnimation: animation forKey:@”key”];

...

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag {
       if (theAnimation == [myLayer animationForKey:@”key”]) {
            // Fire another animation
            [myLayer removeAllAnimations];
       }
}

//
λ         λ

•           CAAnimation
    block                     …

• iOS 5
• Lion
Core animation
CALayer

• UILayer -layoutSublayers
•            UIView -layoutSubviews
    …
contents
  CALayer                            Quartz
- (void)drawInContext:(CGContextRef)ctx
{

    UIGraphicsPushContext(ctx);
       //    ctx      current graphics context          :D

    UIBezierPath *path = [UIBezierPath
bezierPathWithRoundedRect:self.bounds cornerRadius:10.0];

    CGContextSaveGState(ctx);

    CGContextAddPath(ctx, path.CGPath);

    CGContextClip(ctx);

    [image drawInRect:self.bounds];

    CGContextRestoreGState(ctx);

    UIGraphicsPopContext();
}
view         layer
                    view

UIGraphicsBeginImageContext(self.bounds.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[self.layer renderInContext:ctx];
UIImage *anImage =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return anImage;

//           :D
Core animation
Mac
Cocoa Drawing   NSView
     CALayer         …
Accessibility
•                                app

•                                 …

•           UIView/UIControl
    Accessibility              CALayer
                        Accessibility
Das ist alles.

More Related Content

KEY
Input Method Kit
PDF
XQuery in the Cloud
PDF
Benchx: An XQuery benchmarking web application
PDF
XQuery Rocks
PDF
Cutting Edge Data Processing with PHP & XQuery
PDF
Not your Grandma's XQuery
PDF
Intro to sbt-web
PDF
Intro to Scala.js - Scala UG Cologne
Input Method Kit
XQuery in the Cloud
Benchx: An XQuery benchmarking web application
XQuery Rocks
Cutting Edge Data Processing with PHP & XQuery
Not your Grandma's XQuery
Intro to sbt-web
Intro to Scala.js - Scala UG Cologne

What's hot (18)

PPTX
Introduction to underscore.js
PDF
Developing iOS REST Applications
PPTX
Infrastructure as Code in AWS using Cloudformation
PPS
Underscore
KEY
Underscore.js
PDF
Simpler Core Data with RubyMotion
KEY
コードで学ぶドメイン駆動設計入門
PDF
Integrating React.js Into a PHP Application
PDF
Hi performance table views with QuartzCore and CoreText
PPTX
Introduction to Underscore.js
PDF
iOS Reactive Cocoa Pipeline
PDF
Cassandra Day Chicago 2015: Building Java Applications with Apache Cassandra
PDF
ERGroupware
PDF
Digital Ocean Presentation - Ruby Dev Stackup - The Flatiron School
PPTX
Rethinking Best Practices
PDF
Laravel 8 export data as excel file with example
PDF
Converting a Rails application to Node.js
PPT
Angular js meetup
Introduction to underscore.js
Developing iOS REST Applications
Infrastructure as Code in AWS using Cloudformation
Underscore
Underscore.js
Simpler Core Data with RubyMotion
コードで学ぶドメイン駆動設計入門
Integrating React.js Into a PHP Application
Hi performance table views with QuartzCore and CoreText
Introduction to Underscore.js
iOS Reactive Cocoa Pipeline
Cassandra Day Chicago 2015: Building Java Applications with Apache Cassandra
ERGroupware
Digital Ocean Presentation - Ruby Dev Stackup - The Flatiron School
Rethinking Best Practices
Laravel 8 export data as excel file with example
Converting a Rails application to Node.js
Angular js meetup
Ad

Similar to Core animation (20)

PDF
iOS Core Animation
PDF
Core Animation
KEY
iPhone/iPad开发讲座 第五讲 定制视图和多点触摸
PDF
Building animated UI with Core Animation
PDF
Core animation taobao
PDF
Starting Core Animation
PDF
The Great CALayer Tour
PDF
Core Animation
PDF
A short guide to animations in iOS
KEY
I phone勉強会 (2011.11.23)
KEY
Animation in iOS
PDF
CocoaHeads Paris - CATransaction: What the flush?!
KEY
iOSインタラクションデザイン
PDF
animations
PDF
Crafting interactions with Core Animations, David Ortinau
PDF
Александр Зимин – Анимация как средство самовыражения
PDF
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014
PDF
Drawing with Quartz on iOS
PDF
Ui perfomance
PPTX
Animations & swift
iOS Core Animation
Core Animation
iPhone/iPad开发讲座 第五讲 定制视图和多点触摸
Building animated UI with Core Animation
Core animation taobao
Starting Core Animation
The Great CALayer Tour
Core Animation
A short guide to animations in iOS
I phone勉強会 (2011.11.23)
Animation in iOS
CocoaHeads Paris - CATransaction: What the flush?!
iOSインタラクションデザイン
animations
Crafting interactions with Core Animations, David Ortinau
Александр Зимин – Анимация как средство самовыражения
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014
Drawing with Quartz on iOS
Ui perfomance
Animations & swift
Ad

More from Weizhong Yang (20)

PDF
Flutter BLE
PDF
怎樣在 Flutter app 中使用 Google Maps
PDF
關於延長役期這件事情
PDF
Dart null safety
PDF
導入 Flutter 前你應該知道的事
PDF
Github Actions
PDF
iPlayground: CarPlay and MFI Hearing Aids
PDF
CocoaPods private repo
PDF
Flutter 踩雷心得
PDF
那些年被蘋果 Ban 掉的 API
PDF
給 iOS 工程師的 Flutter 開發
PDF
給 iOS 工程師的 Vue.js 開發
PDF
苦集滅道:透過開發客製 Sketch Plug-in 改善產品設計流程
PDF
使用 switch/case 重構程式碼
PDF
怎樣寫出比較沒有問題的 Code
PDF
貪食蛇
PDF
Aspect Oriented Programming
PDF
Mac OS X 與 iOS 的 Audio API
KEY
Html 5 native drag
KEY
Retina mac
Flutter BLE
怎樣在 Flutter app 中使用 Google Maps
關於延長役期這件事情
Dart null safety
導入 Flutter 前你應該知道的事
Github Actions
iPlayground: CarPlay and MFI Hearing Aids
CocoaPods private repo
Flutter 踩雷心得
那些年被蘋果 Ban 掉的 API
給 iOS 工程師的 Flutter 開發
給 iOS 工程師的 Vue.js 開發
苦集滅道:透過開發客製 Sketch Plug-in 改善產品設計流程
使用 switch/case 重構程式碼
怎樣寫出比較沒有問題的 Code
貪食蛇
Aspect Oriented Programming
Mac OS X 與 iOS 的 Audio API
Html 5 native drag
Retina mac

Core animation

Editor's Notes