Core Animation based on Quartz provides very simple ways to create special effects in your game or application.
The following shows how to create a Move Effect of any UIView (e.g. UIButtonView, UIImageView etc.)
- +(void)move:(UIView*)view to:(CGPoint)point withDuration:(int) duration andSnapBack:(BOOL) snapBack
- {
- // Prepare the animation from the current position to the new position
- CABasicAnimation *animation =[CABasicAnimation animationWithKeyPath:@"position"];
- animation.fromValue =[view.layer valueForKey:@"position"];
- // iOS
- animation.toValue =[NSValue valueWithCGPoint:point];
- animation.duration = duration;
- if(!snapBack)
- {
- // Update the layer's position so that the layer doesn't snap back when the animation completes.
- view.layer.position = point;
- }
- // Add the animation, overriding the implicit animation.
- [view.layer addAnimation:animation forKey:@"position"];
- }