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 setDuration:6.0]; //seconds

[anim setCalculationMode:kCAAnimationCubic];

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



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s