This past Tuesday iOS developers from across the metroplex gathered at Google's new digs in Boulder. The night started with some brief announcements from meetup leader Justin Shacklette who informed us that his first iPad game Jab-a-Face has finally made it into the app store. Congrats Justin!
Our guest speaker was Paul Franceus of Google, and his presentation was titled "Get Moving with Core Animation." I really enjoyed Paul's presentation, and he made it easy to see how powerful Core Animation is. Paul outlined that there are really two main ways to animate layers with Core Animation: implicit animations and explicit animations.
Implicit Animations
These animations take much less code to get working. Developers simply change the properties of layers and use [UIView commitAnimations] to trigger all the animations at once. The default duration for these animations is .25 seconds. Great for fading stuff in and out. Paul was praising Core Animation all night saying "it just figures it out." This definitely seems like the lazy man's way to simple animations.
<br /> view.center = CGPointMake(center.x + xOffset, center.y + yOffset);<br /> CGRect newBounds = CGRectMake(0, 0, subviewSize_.width,<br /> subviewSize_.height);<br /> CGFloat scale = [GraphicsUtils scaleForSize:view.bounds.size<br /> inRect:newBounds];<br /> CGAffineTransform scaleAndRotate =<br /> CGAffineTransformRotate(CGAffineTransformMakeScale(scale, scale),<br /> angle * index + M_PI_2);<br /> view.transform = scaleAndRotate;<br /> [UIView commitAnimations];<br />
Explicit Animations
These animation give you more control. You start by declaring a CABasicAnimation object and then setting all the appropriate properties you want to manipulate. After you've created the animation object you then add the animation to the layer.
<br /> CABasicAnimation *wobble = [CABasicAnimation animationWithKeyPath:<br /> @"transform.rotation.z"];<br /> wobble.timingFunction = [CAMediaTimingFunction<br /> functionWithName:kCAMediaTimingFunctionEaseInEaseOut];<br /> wobble.duration = 0.1 + (rand() % 10) * 0.005;<br /> wobble.repeatCount = HUGE_VALF;<br /> wobble.autoreverses = YES;<br /> wobble.fromValue = [NSNumber numberWithFloat:DEGREES_TO_RADIANS(5)];<br /> wobble.toValue = [NSNumber numberWithFloat:-DEGREES_TO_RADIANS(5)];<br /> [layer addAnimation:wobble forKey:@"transform.rotation.z"];<br />
Paul discussed several fun aspects of Core Animation, but the one I liked the most was the idea of group animations. Grouped animations allow you to set up several animations on one layer and then trigger them at once.
He also discussed some of the performance issues he and his team encountered when they were making Google Books for the iPhone. He said that performance starts to suffer around 200+ layers on screen at once. Paul also said that performance issues can occur with multiple layers that have their opacity turned down. When asked how to tell the difference between Core Animation and Open GL animations, Paul showed us the page flip animation in Google books which is true 3D animation. Core animation only allows for 2.5D animation, which is really morphing a 2D object to make it appear like it has a third dimension.
Paul said that he and his team went to WWDC and they were very impressed with some of the new features in Core Animation for iOS 5. He refused to tell us what they were. :) Throughout the presentation he also made references to Core Animation being used in Lion, Apple's new version of OS X.
The code samples above were taken from his presentation. You can find the demo source code here.