Graphics Reference
In-Depth Information
@implementation ViewController
- ( void )viewDidLoad
{
[ super viewDidLoad ];
//create a red layer
self .colorView = [[ UIView alloc ] init ];
self .colorView. bounds = CGRectMake ( 0 , 0 , 100 , 100 );
self .colorView. center = CGPointMake ( self . view . bounds . size . width / 2 ,
self . view . bounds . size . height / 2 );
self .colorView. backgroundColor = [ UIColor redColor ];
[ self . view addSubview : self .colorView];
}
- ( void )touchesBegan:( NSSet *)touches withEvent:( UIEvent *)event
{
//perform the animation
[ UIView animateWithDuration : 1.0
delay : 0.0
options : UIViewAnimationOptionCurveEaseOut
animations :^{
//set the position
self .colorView. center =
[[touches anyObject ] locationInView : self . view ];
} completion : NULL ];
}
@end
Easing and Keyframe Animations
You may recall that the color switching keyframe animation from Chapter 8 (refer to
Listing 8.5) looked a bit odd due to the linear pacing between colors, which made the
transition between them occur in an unnatural fashion. To correct that, we can apply a more
appropriate easing function such as kCAMediaTimingFunctionEaseIn , which will add a
slight pulse effect as the layer changes color—more like a colored light bulb would behave
in real life.
We don't want to apply the function uniformly across the whole animation, though; we
want to repeat the easing for each animation step so that each color transition pulses in turn.
Search WWH ::




Custom Search