#import "ViewController.h"#defineAngle2rad (angle) ((angle)/180.0 * M_PI)@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 { /** 1:uibezierpath: Is the class that draws the path, moveToPoint sets the starting point, Addlinetopoint, draws a path from the beginning, and in the execution Addlinetopoint, from the end point as the starting point, in drawing a path, To Cgpath **/ //1. Create an Animated objectCakeyframeanimation *anim =[cakeyframeanimation animation]; Anim.duration=2; Uibezierpath*path =[Uibezierpath Bezierpath]; [Path Movetopoint:cgpointmake ( -, -)]; [Path Addlinetopoint:cgpointmake ( -, -)]; [Path Addlinetopoint:cgpointmake ( -, -)]; Anim.keypath=@"position"; Anim.path=path. Cgpath; [Self.imageV.layer Addanimation:anim forkey:nil];}//icon Jitter- (void) icon {//1. Create an Animated objectCakeyframeanimation *anim =[cakeyframeanimation animation]; //2. Setting Property values /*The keypath path for a property under Layear is an array, and the object defined in the values array will animate, *1:keypath the icon to the left-3 radians, then animates back to 3 radians, moving to 3 in the animation, Infinite Repetition 2: You can also set the rollover effect of the animation: Anim.values = @[@ (Angle2rad ( -3)), @ (Angle2rad (3)), Anim.autoreverses, so that after the execution of the values in the animation to 3 radians, will also be animated back to continue to repeat, otherwise it will not produce animation 3: Then add the animation to the Layear layer, the core animation is the role of smashing layear layer **/Anim.keypath=@"transform.rotation"; Anim.values= @[@ (Angle2rad (-3), @ (Angle2rad (3), @ (Angle2rad (-3))]; //3. Set Animation execution timesAnim.repeatcount =maxfloat; Anim.duration=0.5; //anim.autoreverses = YES;[Self.imageV.layer Addanimation:anim Forkey:nil]; }@end
1. Introduction of Frame Animation:
Cakeyframeanimation It can animate between multiple values.
To set the properties between multiple values:
The following is an array, which is the number of values to set.
Anim.values = @[];
It can also be animated according to a path.
Anim.path = path created by itself.
2. Picture jitter Ideas:
is actually to make a rotation around the animation. First let it rotate to the left-5, then to the right 5 degrees, and then from 5 degrees to 5 degrees.
There will be sway around the effect.
Specific implementation code
Create a Frame animation
Cakeyframeanimation *anim = [cakeyframeanimation animation];
Set animation properties to rotate
Anim.keypath = @ "Transform.rotation";
Setting property values to multiple properties
Anim.values = @[@ (Angle2radio ( -5)), @ (Angle2radio (5)), @ (Angle2radio (-5))];
Set animation execution times
Anim.repeatcount = maxfloat;
Add animations
[_imageview.layer Addanimation:anim Forkey:nil];
3. The effect of moving according to the circular path.
Create path
Uibezierpath *path = [Uibezierpath
Bezierpathwithovalinrect:cgrectmake (50, 50, 100, 100)];
[Path Addlinetopoint:cgpointmake (200, 500)];
Set the path to the animated property
Anim.path = path. Cgpath;
iOS Development core Animation Five: icon jitter effect--cakeyframeanimation