Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Mastering Core Animation
Search
Felix Chern
September 10, 2012
Technology
3
940
Mastering Core Animation
A walkthrough of Core Animation framework
Felix Chern
September 10, 2012
Tweet
Share
More Decks by Felix Chern
See All by Felix Chern
達到硬體極限的演算法設計
dryman
0
380
Atomic programming
dryman
0
280
我在廣告業學到的 大數據實戰技巧
dryman
1
1.2k
Introduction to Big Data Engineering
dryman
1
500
Type qualifier and friends
dryman
1
110
Other Decks in Technology
See All in Technology
明日からできる!技術的負債の返済を加速するための実践ガイド~『ホットペッパービューティー』の事例をもとに~
recruitengineers
PRO
3
380
2025-02-21 ゆるSRE勉強会 Enhancing SRE Using AI
yoshiiryo1
1
160
一度 Expo の採用を断念したけど、 再度 Expo の導入を検討している話
ichiki1023
1
160
ハッキングの世界に迫る~攻撃者の思考で考えるセキュリティ~
nomizone
13
5.1k
2/18/25: Java meets AI: Build LLM-Powered Apps with LangChain4j
edeandrea
PRO
0
110
技術的負債解消の取り組みと専門チームのお話 #技術的負債_Findy
bengo4com
1
1.3k
目の前の仕事と向き合うことで成長できる - 仕事とスキルを広げる / Every little bit counts
soudai
24
7k
レビューを増やしつつ 高評価維持するテクニック
tsuzuki817
1
670
30分でわかる『アジャイルデータモデリング』
hanon52_
9
2.6k
OpenID Connect for Identity Assurance の概要と翻訳版のご紹介 / 20250219-BizDay17-OIDC4IDA-Intro
oidfj
0
260
開発スピードは上がっている…品質はどうする? スピードと品質を両立させるためのプロダクト開発の進め方とは #DevSumi #DevSumiB / Agile And Quality
nihonbuson
2
2.8k
モノレポ開発のエラー、誰が見る?Datadog で実現する適切なトリアージとエスカレーション
biwashi
6
800
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.1k
Into the Great Unknown - MozCon
thekraken
35
1.6k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
How to Think Like a Performance Engineer
csswizardry
22
1.3k
Mobile First: as difficult as doing things right
swwweet
223
9.3k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Designing for humans not robots
tammielis
250
25k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
193
16k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
133
33k
GraphQLとの向き合い方2022年版
quramy
44
13k
Optimizing for Happiness
mojombo
376
70k
Transcript
Mastering Core Animation Felix Chern (dryman) 12年9月10日星期⼀一
Felix Chern (dryman) Research assistant & iOS developer github id:
idryman twitter id: @idryman blog: idryman.org 12年9月10日星期⼀一
Core Animation • Low level objective c rendering and animation
classes used by UIView and UIKit • High performance rendering with simple programming model • Lightweight data structure 12年9月10日星期⼀一
- classes • CAAnimation • CAAnimationGroup • CABasicAnimation • CADisplayLink
• CAEAGLLayer • CAKeyframeAnimation • CALayer • CAEmitterCell • CAEmitterLayer • CAGradientLayer • CAMediaTimingFunction • CAPropertyAnimation • CAScrollLayer • CATextLayer • CATiledLayer • CATransaction • CATransition - protocols • CAAction • CALayoutManager • CAMediaTiming QuartzCore/QuartzCore.h 12年9月10日星期⼀一
- classes • CAAnimation • CAAnimationGroup • CABasicAnimation • CADisplayLink
• CAEAGLLayer • CAKeyframeAnimation • CALayer • CAEmitterCell • CAEmitterLayer • CAGradientLayer • CAMediaTimingFunction • CAPropertyAnimation • CAScrollLayer • CATextLayer • CATiledLayer • CATransaction • CATransition - protocols • CAAction • CALayoutManager • CAMediaTiming Layer provides contents 12年9月10日星期⼀一
- classes • CAAnimation • CAAnimationGroup • CABasicAnimation • CADisplayLink
• CAEAGLLayer • CAKeyframeAnimation • CALayer • CAEmitterCell • CAEmitterLayer • CAGradientLayer • CAMediaTimingFunction • CAPropertyAnimation • CAScrollLayer • CATextLayer • CATiledLayer • CATransaction • CATransition - protocols • CAAction • CALayoutManager • CAMediaTiming Animation defines how properties are animated 12年9月10日星期⼀一
- classes • CAAnimation • CAAnimationGroup • CABasicAnimation • CADisplayLink
• CAEAGLLayer • CAKeyframeAnimation • CALayer • CAEmitterCell • CAEmitterLayer • CAGradientLayer • CAMediaTimingFunction • CAPropertyAnimation • CAScrollLayer • CATextLayer • CATiledLayer • CATransaction • CATransition - protocols • CAAction • CALayoutManager • CAMediaTiming These allows you to create custom animations and Core Animation add-ons 12年9月10日星期⼀一
• Much like UIView • can set content image, or
draw with Quartz 2D • When you change properties, you will trigger implicit animations CALayer Emitter Layer and Cells CALayer with border and corner radius 12年9月10日星期⼀一
CAAnimation • implicit • layer.position = CGPointMake(x,y); • explicit •
setup CAAnimation • layer addAnimation: forKey: • layer removeAnimationForKey: 12年9月10日星期⼀一
Explicit CAAnimation CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"]; animation.fromValue = @1.0;
animation.toValue = @0.0; animation.autoreverse = YES; animation.repeatCount = INFINITY; animation.duration = 2.0; [layer addAnimation: animation forKey:@"animateOpacity"]; 12年9月10日星期⼀一
time property CABasicAnimation fromValue: toValue: 12年9月10日星期⼀一
time property CABasicAnimation fromValue: toValue: 12年9月10日星期⼀一
time property CABasicAnimation fromValue: toValue: time property CAKeyFrameAnimation fromValue: toValue:
12年9月10日星期⼀一
time property CABasicAnimation fromValue: toValue: time property CAKeyFrameAnimation fromValue: toValue:
NSString * const kCAAnimationLinear; NSString * const kCAAnimationDiscrete; NSString * const kCAAnimationPaced; NSString * const kCAAnimationCubic; NSString * const kCAAnimationCubicPaced; 12年9月10日星期⼀一
CALayer Properties 1 frame property 2 bounds property 3 position
property 4 zPosition property 5 anchorPointZ property 6 anchorPoint property 7 contentsScale property 8 – affineTransform 9 – setAffineTransform: 10 transform property 11 sublayerTransform property 1 contentsGravity property 2 opacity property 3 hidden property 4 masksToBounds property 5 doubleSided property 6 mask property 7 cornerRadius property 8 borderWidth property 9 borderColor property 10 backgroundColor property 11 backgroundFilters property 12 shadowOpacity property 13 shadowRadius property 14 shadowOffset property 15 shadowColor property 16 shadowPath property 17 filters property 18 compositingFilter property 19 style property Most Animations can be created by CAAnimation and CALayer Properties! 12年9月10日星期⼀一
Excepts... 12年9月10日星期⼀一
• Scrolling • Animation related to motion • Animation related
to AVFoundation inputs • Animation related to other continuous event sources In these cases, we need to control frames ourselves 12年9月10日星期⼀一
• Pros: • Won’t miss any data sources • Easier
to implement with delegates • Cons: • Does not allow frame drop • Harder to control timing Push based 12年9月10日星期⼀一
Pull based • Pros • Let CADisplayLink setup runloop, timing,
and everything else • Cons • Event source has to be pullable 12年9月10日星期⼀一
-(void)update { float x_acc, y_acc, phi, a_eff; if (self.sharedManager.accelerometerActive) {
CMAccelerometerData *accData = self.sharedManager.accelerometerData; x_acc = accData.acceleration.x; y_acc = accData.acceleration.y; } else { x_acc = 0; y_acc = -1.0; } /* calculations */ [CATransaction begin]; [CATransaction setDisableActions:YES]; self.bar1.angle = self.current[0]; self.bar2.angle = self.current[1]; self.bar2.position = self.bar1.tailPosition; self.emitterLayer.emitterPosition = self.bar1.tailPosition; self.emitterCell.birthRate = floorf(fabsf(self.current[2]-self.current[3])*10); self.emitterCell.velocity = fabsf(self.bar1.length*self.current[2]); [CATransaction commit]; } _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(update)]; [self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode]; Pull data from accelerometer Disable implicit animation Setup CADisplayLink for updating data Use [_displayLink setPause:YES] to stop animation 12年9月10日星期⼀一
Custom CAAnimation • Use CADisplayLink for runloop • CATransaction for
stoping implicit animation • Confirms to CAMediaTiming protocol • Use CACurrentMediaTime to pull timestamp 12年9月10日星期⼀一
Tips and Tricks 12年9月10日星期⼀一
KeyValue Coding [mySubLayer setName: @"rocket"]; otherLayer.emitterCells = @[mySubLayer, ...]; [otherLayer
setValue: @3.0 forKeyPath: @"emitterCells.rocket.emissionRange"]; 12年9月10日星期⼀一
More on explicit Animation [CATranscation begin]; [CATranscation setDisableActions:YES]; circleLayer.opacity =
0; CABasicAnimation *fade; fade = [CABasicAnimation animationWithKeyPath:@"opacity"]; fade.duration = 1; fade.fromValue = @1.0; fade.toValue = @0.0; fade.beginTime = CACurrentMediaTime() + 3.0; [circleLayer addAnimation:fade forKey:@"fade"]; [CATranscation commit]; The layer opacity will be 0 after the animation ends 12年9月10日星期⼀一
CAEmitterLayer & CAEmitterCell Off screen rendering 12年9月10日星期⼀一
Instruments 12年9月10日星期⼀一
Instruments 12年9月10日星期⼀一
Instruments 12年9月10日星期⼀一
Instruments 12年9月10日星期⼀一
Instruments 12年9月10日星期⼀一
References • WWDC 2011 section 421: Core Animation Essentials •
WWDC 2012 section 211: Building Concurrent User Interface on iOS • WWDC 2012 section 235: iOS App Performance: Responsiveness • WWDC 2012 section 238: iOS App Performance: Graphics and Animations • WWDC 2012 section 506: Optimizing 2D Graphics and Animation Performances • iOS 5 programming -- Pushing the limits ISBN: 1119961327 12年9月10日星期⼀一
Questions? 12年9月10日星期⼀一