Graphics Reference
In-Depth Information
- ( void )touchesBegan:( NSSet *)touches withEvent:( UIEvent *)event
{
//configure the transaction
[ CATransaction begin ];
[ CATransaction setAnimationDuration : 1.0 ];
[ CATransaction setAnimationTimingFunction :
[ CAMediaTimingFunction functionWithName : kCAMediaTimingFunctionEaseOut ]];
//set the position
self .colorLayer. position = [[touches anyObject ] locationInView : self . view ];
//commit transaction
[ CATransaction commit ];
}
@end
UIView Animation Easing
UIKit's animation methods also support the use of easing functions, although the syntax
and constants are different. To change the easing for the UIView animation methods, add
one of the following constants to the options parameter for the animation:
UIViewAnimationOptionCurveEaseInOut
UIViewAnimationOptionCurveEaseIn
UIViewAnimationOptionCurveEaseOut
UIViewAnimationOptionCurveLinear
These correspond directly to their CAMediaTimingFunction counterparts.
UIViewAnimationOptionCurveEaseInOut is the default value that will be used unless you
specify otherwise. (There is no counterpart in UIKit for
kCAMediaTimingFunctionDefault .)
See Listing 10.2 for how these functions are used. (Note that we have switched from using
a hosted layer to a UIView in this example because UIKit animation doesn't work with
hosted layers.)
Listing 10.2 Easing Test Project Converted to Use UIKit Animation
@interface ViewController ()
@property ( nonatomic , strong ) UIView *colorView;
@end
Search WWH ::




Custom Search