Core animation of iOS development: Core animation-core animation--cabasicanimation Basic Core Animation

Source: Internet
Author: User

#import "ViewController.h"@interfaceViewcontroller () @property (weak, nonatomic) Iboutlet UIView*Redview;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //additional setup after loading the view, typically from a nib.            }-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *)Event {        //1. Create an Animated object (set the property value of the layer.)Cabasicanimation *anim =[cabasicanimation animation]; //2. Setting Property valuesAnim.keypath =@"position.x"; Anim.tovalue= @ -; //animations are automatically deleted when the animation is completeAnim.removedoncompletion =NO; Anim.fillmode=@"forwards"; //3. Add Animation: The key value is to distinguish between different animations[Self.redView.layer Addanimation:anim Forkey:nil]; }

The function of the core animation is above the layer.

The essence of animation is to change one of the properties of a layer.

Cabasicanimation *anim = [cabasicanimation animation];

The layers have those attributes, which can be written here.

Anim.keypath = @ "Transform.scale";

Anim.tovalue = @0.5;

Tell the animation not to remove when finished

Anim.removedoncompletion = NO;

saves the front-most effect of the animation. The effect of the last setting

Anim.fillmode = Kcafillmodeforwards;

Add animations to the layer.

[_redview.layer Addanimation:anim Forkey:nil];

Second: Heartbeat effect

#import "ViewController.h"@interfaceViewcontroller () @property (weak, nonatomic) Iboutlet Uiimageview*Imagev;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //additional setup after loading the view, typically from a nib.}-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *)Event {        //Create an animated objectCabasicanimation *anim =[cabasicanimation animation]; //Setting property valuesAnim.keypath =@"Transform.scale"; Anim.tovalue= @0; //set animation execution timesAnim.repeatcount =maxfloat; //set Animation execution durationAnim.duration =3; //Auto Reverse (how to get back)Anim.autoreverses =YES; //Add animations[Self.imageV.layer Addanimation:anim Forkey:nil]; }- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}@end

Idea: Just let a picture do a small zoom and zoom animation.

Code implementation:

Cabasicanimation *anim =[cabasicanimation Animation];

Set scaling Properties

Anim.keypath = @ "Transform.scale";

Zoom to Minimum

Anim.tovalue = @0;

Set the number of times an animation executes

Anim.repeatcount = maxfloat;

Set the length of time the animation executes

Anim.duration = 0.25;

Set animation auto-invert (how to go, how to return)

anim.autoreverses = YES;

Add animations

[Self.heartView.layer Addanimation:anim Forkey:nil];

Core animation of iOS development: Core animation-core animation--cabasicanimation Basic Core Animation

Related Article

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.