Sample of Keyframe Animations in ios

CALayer *layer = [CALayer layer];

[layer setPosition:CGPointMake(100.0, 100.0)];

[layer setBounds:CGRectMake(0.0, 0.0, 50.0, 60.0)];

[layer setBackgroundColor:[[UIColor redColor] CGColor]];

[self.view.layer addSublayer:layer];

 

CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@”position”];

 

//NSArray *times = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:0.33], [NSNumber numberWithFloat:0.5], [NSNumber numberWithFloat:1.0], nil];

//[anim setKeyTimes:times];

 

NSArray *values = [NSArray arrayWithObjects:[NSValue valueWithCGPoint:CGPointMake(100., 100.)], 

  [NSValue valueWithCGPoint:CGPointMake(100., 200.)],

  [NSValue valueWithCGPoint:CGPointMake(220., 200.)], 

  [NSValue valueWithCGPoint:CGPointMake(220., 100.)], nil];

[anim setValues:values];

    anim.repeatCount=5;

[anim setDuration:6.0]; //seconds

[anim setCalculationMode:kCAAnimationCubic];

[layer addAnimation:anim forKey:@”position”];