SlideShare uma empresa Scribd logo
1 de 27
Baixar para ler offline
Learning Core Animation
Louis Zhu
13年6月3日星期⼀一
13年6月3日星期⼀一
Layer
13年6月3日星期⼀一
Layer
• The key of Core Animation
• Merely manages the state information surrounding a
bitmap
• Consider as model in MVC
13年6月3日星期⼀一
13年6月3日星期⼀一
13年6月3日星期⼀一
Transform
struct CATransform3D
{
CGFloat m11, m12, m13, m14;
CGFloat m21, m22, m23, m24;
CGFloat m31, m32, m33, m34;
CGFloat m41, m42, m43, m44;
};
13年6月3日星期⼀一
Presentation layer
13年6月3日星期⼀一
Provide contents
• Using an image
• Using a delegate
13年6月3日星期⼀一
Using an image
CALayer *layer = someView.layer;
layer.contents = (id)someCGImage;
layer.contentScale = kScreenScale;
13年6月3日星期⼀一
Using a delegate
- (void)displayLayer:(CALayer *)theLayer {
// Check the value of some state property
if (self.displayYesImage) {
// Display the Yes image
theLayer.contents = [someHelperObject loadStateYesImage];
}
else {
// Display the No image
theLayer.contents = [someHelperObject loadStateNoImage];
}
}
13年6月3日星期⼀一
Using a delegate
- (void)drawLayer:(CALayer *)theLayer inContext:
(CGContextRef)theContext {
CGMutablePathRef thePath = CGPathCreateMutable();
CGPathMoveToPoint(thePath,NULL,15.0f,15.f);
CGPathAddCurveToPoint(thePath,
NULL,
15.f,250.0f,
295.0f,250.0f,
295.0f,15.0f);
CGContextBeginPath(theContext);
CGContextAddPath(theContext, thePath);
CGContextSetLineWidth(theContext, 5);
CGContextStrokePath(theContext);
CFRelease(thePath);
}
13年6月3日星期⼀一
Layer’s appearance
@property(copy) NSString *contentsGravity;
@property CGFloat contentsScale;
@property CGColorRef backgroundColor;
@property CGFloat cornerRadius;
@property CGFloat borderWidth;
@property CGColorRef borderColor;
@property float opacity;
@property(copy) NSArray *filters;
@property CGColorRef shadowColor;
@property float shadowOpacity;
@property CGSize shadowOffset;
13年6月3日星期⼀一
Basic animation
13年6月3日星期⼀一
Basic animation
• CABasicAnimation
• keyPath
• fromValue
• toValue
• duration
13年6月3日星期⼀一
Demo
13年6月3日星期⼀一
Keyframe animation
13年6月3日星期⼀一
Using path
- (void)animatePosition {
CAKeyframeAnimation *theAnimation =
[CAKeyframeAnimation animationWithKeyPath:@"position"];
theAnimation.path = someCGPath;
theAnimation.duration = 5.0;
[theLayer addAnimation:theAnimation forKey:@"position"];
}
13年6月3日星期⼀一
Demo
13年6月3日星期⼀一
Specify values and timing
- (void)animateBorder {
CAKeyframeAnimation *widthAnimation = [CAKeyframeAnimation
animationWithKeyPath:@"borderWidth"];
NSArray *widthValues = @[@1.0, @10.0, @5.0, @0.0];
widthAnimation.values = widthValues;
widthAnimation.calculationMode = kCAAnimationPaced;
widthAnimation.keyTimes = @[@0.0f, @0.66667f, @1.0f];
[theLayer addAnimation:widthAnimation forKey:@"borderWidth"];
}
13年6月3日星期⼀一
Multiple animations
CAAnimationGroup *group = [CAAnimationGroup animation];
group.animations = @[animation0, animation1];
group.duration = 5.0;
[layer addAnimation:group forKey:@"groupedAnimations"];
13年6月3日星期⼀一
Demo
13年6月3日星期⼀一
Stop an animation
[theLayer addAnimation:theAnimation forKey:@"animationKey"];
// somedays later
[theLayer removeAnimationForKey:@"animationKey"];
13年6月3日星期⼀一
Detecting animation’s end
// invoking in the delegate
- (void)animationDidStart:(CAAnimation *)theAnimation
- (void)animationDidStop:(CAAnimation *)theAnimation finished:
(BOOL)flag
13年6月3日星期⼀一
One more thing...
13年6月3日星期⼀一
Animatable properties
• http://developer.apple.com/library/ios/
documentation/Cocoa/Conceptual/
CoreAnimation_guide/AnimatableProperties/
AnimatableProperties.html#//apple_ref/doc/uid/
TP40004514-CH11-SW1
13年6月3日星期⼀一
13年6月3日星期⼀一

Mais conteúdo relacionado

Destaque

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Destaque (20)

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 

Learning Core Animation