iOS Learning note 28-base animations and keyframe animations

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.