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
Introduction To Core Animation (CocoaConf Chica...
Search
corvino
March 27, 2015
Technology
1
75
Introduction To Core Animation (CocoaConf Chicago March 2015)
corvino
March 27, 2015
Tweet
Share
More Decks by corvino
See All by corvino
Core Animation for the Masses
corvino
0
67
Other Decks in Technology
See All in Technology
学生・新卒・ジュニアから目指すSRE
hiroyaonoe
2
730
マネージャー視点で考えるプロダクトエンジニアの評価 / Evaluating Product Engineers from a Manager's Perspective
hiro_torii
0
130
インフラエンジニア必見!Kubernetesを用いたクラウドネイティブ設計ポイント大全
daitak
1
380
22nd ACRi Webinar - NTT Kawahara-san's slide
nao_sumikawa
0
100
CDKで始めるTypeScript開発のススメ
tsukuboshi
1
520
Embedded SREの終わりを設計する 「なんとなく」から計画的な自立支援へ
sansantech
PRO
3
2.6k
生成AIを活用した音声文字起こしシステムの2つの構築パターンについて
miu_crescent
PRO
3
220
マーケットプレイス版Oracle WebCenter Content For OCI
oracle4engineer
PRO
5
1.6k
Red Hat OpenStack Services on OpenShift
tamemiya
0
130
15 years with Rails and DDD (AI Edition)
andrzejkrzywda
0
200
小さく始めるBCP ― 多プロダクト環境で始める最初の一歩
kekke_n
1
530
AI駆動開発を事業のコアに置く
tasukuonizawa
1
340
Featured
See All Featured
The Mindset for Success: Future Career Progression
greggifford
PRO
0
240
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
130
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
430
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.3k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
250
Are puppies a ranking factor?
jonoalderson
1
2.7k
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
sira's awesome portfolio website redesign presentation
elsirapls
0
150
Producing Creativity
orderedlist
PRO
348
40k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.7k
Balancing Empowerment & Direction
lara
5
890
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
Transcript
Introduction to Core Animation Nathan Corvino March 27, 2015
UIView Animations [UIView animateWithDuration:1.2 animations:^{ self.targetView.bounds = CGRectMake(0., 0., 100.,
100.); self.targetView.center = CGPointMake(50., 50); self.targetView.backgroundColor = [UIColor redColor]; self.targetView.alpha = 0.5; }];
None
CALayer • Manage content, geometry, and visual attributes • Content
Cache (Bitmap/Texture) • GPU!
• anchorPoint • backgroundColor • backgroundFilters • borderColor • borderWidth
• bounds • compositingFilter • contents • contentsRect • cornerRadius • doubleSided • filters • hidden • mask • masksToBounds • opacity • position • shadowColor • shadowOffset • shadowOpacity • shadowPath • shadowRadius • sublayers • sublayerTransform • transform • zPosition
• anchorPoint • backgroundColor • backgroundFilters • borderColor • borderWidth
• bounds • compositingFilter • contents • contentsRect • cornerRadius • doubleSided • filters • hidden • mask • masksToBounds • opacity • position • shadowColor • shadowOffset • shadowOpacity • shadowPath • shadowRadius • sublayers • sublayerTransform • transform • zPosition • frame
Demo
• anchorPoint • backgroundColor • backgroundFilters • borderColor • borderWidth
• bounds • compositingFilter • contents • contentsRect • cornerRadius • doubleSided • filters • hidden • mask • masksToBounds • opacity • position • shadowColor • shadowOffset • shadowOpacity • shadowPath • shadowRadius • sublayers • sublayerTransform • transform • zPosition
• anchorPoint • backgroundColor • backgroundFilters • borderColor • borderWidth
• bounds • compositingFilter • contents • contentsRect • cornerRadius • doubleSided • filters • hidden • mask • masksToBounds • opacity • position • shadowColor • shadowOffset • shadowOpacity • shadowPath • shadowRadius • sublayers • sublayerTransform • transform • zPosition
• anchorPoint • backgroundColor • backgroundFilters • borderColor • borderWidth
• bounds • compositingFilter • contents • contentsRect • cornerRadius • doubleSided • filters • hidden • mask • masksToBounds • opacity • position • shadowColor • shadowOffset • shadowOpacity • shadowPath • shadowRadius • sublayers • sublayerTransform • transform • zPosition
UIView Animations [UIView animateWithDuration:1.0 animations:^{ … }]; [UIView animateWithDuration:1.2 delay:0.
options:UIViewAnimationOptionCurveEaseInOut animations:^{ … } completion:^(BOOL finished) { … }];
UIView Animations [UIView animateWithDuration:1.2 delay:0. options:UIViewAnimationOptionCurveEaseInOut animations:^{ … } completion:^(BOOL
finished) { [UIView animateWithDuration:1.2 delay:0. options:UIViewAnimationOptionCurveEaseInOut animations:^{ … } } completion:^(BOOL finished) { … } }]; Chain Animations
Timing • Linear • EaseIn • EaseOut • EaseIn-EaseOut •
Default • Custom
Linear EaseIn EaseOut EaseIn-EaseOut
Implicit vs Explicit • UIView-based • sublayers • Disable with
CATransaction • CAAnimation
Explicit Animations CABasicAnimation *theAnimation = [CABasicAnimation animationWithKeyPath:@"bounds"]; theAnimation.fromValue = [NSValue
valueWithCGRect:self.targetView.bounds]; theAnimation.toValue = [NSValue valueWithCGRect:newBounds]; theAnimation.duration = 1.2; [self.targetView.layer addAnimation:theAnimation forKey:@"AnimateFrame"]; self.targetView.bounds = newBounds; CABasicAnimation
Explicit Animations • CABasicAnimation • CAAnimationGroup • CAKeyFrameAnimation
Key Frame Animations 1 2 3 4 5
Key Frame Animations
CALayer Subclasses • CAShapeLayer • CATiledLayer • CATextLayer • AV
Layers (CACaptureVideoPreviewLayer, AVPlayerLayer, etc.) • CAGradientLayer • CATextLayer
CAShapeLayer CAShapeLayer *shape = [CAShapeLayer layer]; shape.frame = someFrame; shape.strokeColor
= [UIColor greenColor].CGColor; shape.lineWidth = 3.; shape.fillColor = [UIColor yellowColor].CGColor; shape.path = CGPathCreateWithEllipseInRect( CGRectMake(0., 0., someFrame.size.width, someFrame.size.height), &CGAffineTransformIdentity);
CATiledLayer SomeTiledLayerDelegate *tiledDelegate = [[SomeTiledLayerDelegate alloc] init]; CATiledLayer *tiledLayer =
[CATiledLayer layer]; tiledLayer.delegate = tiledDelegate; tiledLayer.frame = CGRectMake(...); tiledLayer.contentsScale = [[UIScreen mainScreen] scale]; @implementation SomeTiledLayerDelegate - (void)drawLayer:(CALayer*)layer inContext:(CGContextRef)context { CGRect box = CGContextGetClipBoundingBox(context); // ... } @end
Best Practices • Avoid offscreen rendering—Simulator shows • shouldRasterize can
help; it can also hurt. • Blending is still expensive.
Thanks! • @corvino •
[email protected]
• github.com/corvino/LayerExplorer