#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