CABasicAnimation

Basic QuartzCore Framework Animations
//shrinking - scaling
CABasicAnimation* shrink = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
shrink.toValue = [NSNumber numberWithDouble:0.9];
shrink.duration = 0.5;
shrink.delegate = self;
[[targetView layer] addAnimation:shrink forKey:@"shrink"];



//moving
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
theAnimation.duration=0.1;
theAnimation.repeatCount=2;
theAnimation.autoreverses=YES;
theAnimation.fromValue=[NSNumber numberWithFloat:0];
theAnimation.toValue=[NSNumber numberWithFloat:-6];
[[targetView layeraddAnimation:theAnimation forKey:@"animateLayer"];



//rotating
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.rotation"];
theAnimation.duration=0.1;
theAnimation.repeatCount=1;
theAnimation.autoreverses=YES;
theAnimation.fromValue=[NSNumber numberWithFloat:0];
theAnimation.toValue=[NSNumber numberWithFloat:M_PI/3];
[[targetView layeraddAnimation:theAnimation forKey:@"rotateLayer"];


3 comments:

  1. Anonymous2/14/2014

    why does the size becomes the orignal after the completion of animation

    ReplyDelete
    Replies
    1. Anonymous7/06/2014

      if autoreserves value is set to YES the it will return original size, you can set it to NO

      Delete