First create a layer
Calayer *layer = [Calayer layer];
Layer.bounds = CGRectMake (0, 0, 100, 100);
Layer.position = cgpointmake (100, 100);
Layer.backgroundcolor = [Uicolor Yellowcolor]. Cgcolor;
[Self.view.layer Addsublayer:layer];
Self.layer = layer;
Set Up Click events
-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *) event
{
[Self animationscale];
[Self keyanimation];
}
Shrink Animation
-(void) animationscale{
Cabasicanimation *anim = [cabasicanimation animation];
2 Setting up animations
Anim.keypath = @ "bounds";//Pan
Anim.keypath = @ "position";//Zoom
Anim.keypath [email protected] "transform";
which point to reach
Anim.tovalue = [Nsvalue valuewithcgrect:cgrectmake (0, 0, 50, 50)];
Anim.tovalue = [Nsvalue valuewithcgpoint:cgpointmake (300,300)];
Anim.tovalue = [Nsvalue valuewithcatransform3d:catransform3dmakerotation (M_pi_4, 1, 1, 0)];
Anim.duration = 2;
Anim.removedoncompletion = NO;
Anim.fillmode = @ "forwards";
[Self.layer Addanimation:anim Forkey:nil];
}
-(void) keyanimation
{
Cakeyframeanimation *anim = [cakeyframeanimation animationwithkeypath:@ "position"];
Anim.removedoncompletion = NO;
Anim.fillmode = Kcafillmodeforwards;
Anim.duration = 2;
Cgmutablepathref path = cgpathcreatemutable ();
Cgpathaddellipseinrect (Path, NULL, CGRectMake (100, 100, 200, 200));
Anim.path = path;
Anim.timingfunction = [Camediatimingfunction functionwithname:kcamediatimingfunctioneaseout];
[Self.layer Addanimation:anim Forkey:nil];
}
iOS Learning note 28-base animations and keyframe animations