Camediatiming is a protocol (protocol), Caanimation is the parent class of all animation classes, but it cannot be used directly, and its subclasses should be used.
Inheritance Relationship:
Coreanmiation Core Animation Shorthand CA Coreanimation Chinese translation is the core animation, it is a very powerful set of animation processing API, using it can make very beautiful animation effect, and often is more than a multiplier. In other words, very powerful functionality can be achieved with a small amount of code
The UIView animation we used before is essentially coreanimation, but it's just a package of animations inside of him.
View (UIView) supports animated properties with frame Bounds Center Alpha transform and animation delay animation curve (fade animation transition) repetitions
Method:
**********************************************************************
+ (void) Setanimationdelegate: (ID) delegate; agent
+ (void) Setanimationwillstartselector: (SEL) Selector When the animation is about to begin, execute the selector of the delegate object and Beginanimations:context: The parameters passed into the selector
+ (void) Setanimationdidstopselector: (SEL) selector When the animation ends, execute the selector of the delegate object and Beginanimations:context: The parameters passed into the selector
+ (void) Setanimationduration: (Nstimeinterval) The duration of the duration animation, in seconds
+ (void) Setanimationdelay: (nstimeinterval) Delay animation delays the second before starting
+ (void) Setanimationstartdate: (NSDate *) StartDate animation start time, default to now
+ (void) Setanimationcurve: (Uiviewanimationcurve) curve animation Rhythm Control
+ (void) Setanimationrepeatcount: (float) Number of repetitions of repeatcount animations
+ (void) setanimationrepeatautoreverses: (BOOL) repeatautoreverses if set to Yes, the effect of each repetition of the animation is followed by the opposite
+ (void) Setanimationtransition: (uiviewanimationtransition) Transition Forview: (UIView *) View cache: (BOOL) cache Set the transition effect of the view, transition specify the transition type, the cache setting yes represents the use of the view cache, good performance */
**********************************************************************
But Caanimation is the parent class for all animation classes, but it cannot be used directly, and its subclasses should be used. Cabasicanimation, Cakeyframeanimation, Catransition, Caanimationgroup (Capropertyanimation also cannot be used directly, need to use its two subclasses)
Describes all of the above methods and its properties, which can be used by subclasses.
Use case:
1-(void) viewanimation1{2 3/** 4 * Animation Direction 5 * 6 Uiviewanimationtransitionnone, 7 uiviewanimation Transitionflipfromleft, flip 8 uiviewanimationtransitionflipfromright from left, flip 9 uiviewanimationtransitioncurlup from the right, turn up Page Uiviewanimationtransitioncurldown, scroll down 11 */12 13/**14 * Transition status * *16 Uiviewanimationcurveeas Einout, slow-forward//slow at beginning and end17 Uiviewanimationcurveeasein, slow forward/slow at beginning18 Uiviewanimationcurveeaseout, slow out//slow at END19 Uiviewanimationcurvelinear constant 20 */21//*************** 22//Note: The execution of an animation must have a start animation and a commit animation to run an animated transition of UIView// Animation 25//Start animation [UIView beginanimations:@ "JK" context:nil];27 28//Set the direction of the animation [UIView Setanimationtransitio N:uiviewanimationtransitionflipfromright Forview:imageview cache:yes];30 31//Set animation duration [UIView Setanimationdurat ION:5];33 34// Set the state of the animation effect transition [UIView setanimationcurve:uiviewanimationcurveeasein];36 37//Submit animation [UIView Commitanima TIONS];39 40//Detect end of animation [UIView setanimationdelegate:self];42 43//animation near the end, call another method [UIView setanimation Didstopselector: @selector (finishanimation)];45}
Capropertyanimation Property Animation,
The relationship between Calayer and UIView
- In UIView, there is a layer property as the layers, the root layer does not have an implicit animation on the root layer can be placed on the other sublayers, in UIView all can see the content is contained in the layer
- Core Animation is directly acting on calayer, not uiview.
- Calayer responsible for the content and animations displayed in the view
- UIView is responsible for monitoring and responding to events
- Since Calayer at the beginning of the design to consider its animation operations, calayer many properties can be modified to form an animation effect, this property is called "Implicit animation properties."
Calayer is animated when he modifies his properties. This animation is called an implicit animation.
/**
* Property Description Whether implicit animation is supported
The description of the Anchorpoint anchor Point and Anchor Point is the default position at the center point of the image (0.5,0.5) relative to the * own * x, y position ratio, which determines which point of the layer is displayed at the center point.
BackgroundColor Layer Background color is
BorderColor Border Color is
BorderWidth Border Width is
Bounds Layer size is
The contents layer displays content, such as the ability to display a picture as a layer content
Contentsrect layer shows the size and position of the content is
Cornerradius The fillet radius is
Doublesided whether the back of the layer is displayed, by default Yes no
Frame layer size and position, does not support implicit animation, so rarely use frame in calayer, usually use bounds and position instead of no
whether hidden is hidden is
Mask Layer Mask is
Masktobounds Whether the layer boundary is clipped by the child layer, no is the default
Opacity transparency, similar to UIView Alpha, is
Position the position of the layer in the parent view is located in the parent view * Center point location, and the center is similar to UIView
Shadowcolor Shadow color is
Shadowoffset Shadow offset is
Shadowopacity Shadow Transparency, note the default is 0, if setting the shadow must be set this property is
the shape of the Shadowpath shadow is
Shadowradius Shadow Blur radius is
the sublayers sublayer is
Sublayertransform Sub-layer deformation is
Transform layer deformation is
* Above the attributes that support implicit animation the nature of these attributes is that the change by default implies the Cabasicanimation animation implementation
Use of 1.CABasicAnimation:
1 #pragma mark-------------------change position--------------------2-(void) animation1{3 4//*************** Initialization * * * * * * 5///NOTE: Cabasicanimation Use property animation to tell it which property we want to change (passing the property as a string) is important here, and the string cannot be wrong 6 cabasicanimation *animation = [cabasicanimation animationwithkeypath:@ "position"]; 7 8//*************** initialization ***************** 9//Nsvalue has the ability to convert the structure to the ID type 10//Set the animation to that location one at a Animation.tovalue = [Nsvalue valuewithcgpoint:cgpointmake (SHOWLAYER.POSITION.Y)];12 animation.duration = 3;13 14//animated with animated effect The effect goes back to the initial position. animation.autoreverses = yes;16//17//If you want to use Fillmode you must disable Removedoncompletion Edoncompletion = no;19 20//animated effect does not go back to the original position with animation effect Animation.fillmode = kcafillmoderemoved;22//*********** //Kcafillmodeforwards won't be back.//Kcafillmodebackwards will return to//Kcafillmodeboth will not be back 26// Kcafillmoderemoved will return to 27//****************************28 29//Set Slow-forward slow-out animation.timingfunction = [camediatimingfunction functionwithname:kcamediatimingfunctioneaseout];31//Add a Animation to layer [Showlayer addanimation:animation forkey:@ "Move Ke bu xie"];33-}35 #pragma mark-------------------change The rotation of the transform Z--------------------notoginseng-(void) animation3{38 39////The base animator inherits the property name as a key to determine the animation around that property by using the property names CABa Sicanimation *antimation = [cabasicanimation animationwithkeypath:@ "Transform.rotation.z"];41 antimation.fromValue = @ (-0.1);//starting from this position antimation.tovalue = @ (0.1);//To this position end antimation.duration = 0.05;//Duration Antimation.repea TCount = 2;//Repeat 45//whether to animate the effect of returning the antimation.autoreverses = yes;47//Add animation to the layer [Showlayer addanimation: Antimation forkey:@ "Shake"];49}
Use of 2.CAKeyframeAnimation (Keyframe animation):
- Keyframe animation allows us to precisely control the animation effect it is the principle of the animation sequence inside the more critical frame extracted, set its animation effect
- Key frame: 1. Path property to animate trajectory 2.value property to perform the path of the animation track
1 #import "ViewController.h" 2 3 @interface Viewcontroller () 4 {5 calayer *petalayer; 6} 7 @end 8 9 @implementat Ion ViewController10-(void) viewdidload {[Super viewdidload];13//Background map] Uiimageview *iamgeview = [Uiim Ageview alloc]initwithframe:[uiscreen mainscreen].bounds];15 iamgeview.image = [UIImage imagenamed:@ "One"];16 [self . View addsubview:iamgeview];17 [Self addflower];18}19-(void) Addflower21 {UIImage *petal = [UIImage Imagena med:@ "];23" Petalayer = [[calayer alloc]init];24 petalayer.bounds = CGRectMake (0, 0,petal.size.width, Petal.siz E.height); petalayer.position = Cgpointmake (+), petalayer.contents = (ID) petal. cgimage;27 [Self.view.layer addsublayer:petalayer];28}30-(void) dropaanimation{32//Initialize Cakeyframeani mation *drop = [cakeyframeanimation animationwithkeypath:@ "position"];34 drop.duration = 5;35 36//1.************ ************************************************37//Add a few points to change position drop.values = @[[nsvalue Valuewithcgpoint:cgpointmake (+)],[self getpointwithx: Andy:200],[self getpointwithx:-20 andy:200],[self getpointwithx:100 andy:300]];39//***************************** 40 41//2.***************** can also be used in the way of the path can also achieve the effect **********************42//Create Path Cgmutablepathref path = Cgpathcreatemutable (); 44//Add a starting point to the path Cgpathmovetopoint (path, NULL, PETALAYER.P Osition.x, PETALAYER.POSITION.Y); 46//With a starting point you can draw a line from the starting point to another point. Cgpathaddlinetopoint (Path, NULL, Petalayer.positi On.x + +, PETALAYER.POSITION.Y + +); Cgpathaddlinetopoint (path, NULL, petalayer.position.x-100, Petalayer.pos ITION.Y-30); 49//Close path Cgpathclosesubpath (path), Drop.path = path;52 53//release path, si path = nil;55 Drop.removedoncompletion = no;58 Drop.fillmode = Kcafillmodeboth;//does not return to [Petalayer addanimation:drop forkey:@ "DJG"];60-}62-(Nsvalue *) Getpointwithx: (cgfloat) x AndY: (CGF loat) y{64 return [Nsvalue valuewithcgpoint:cgpointmake (x+petalayer.position.x, Y+PETALAYER.POSITION.Y)];66}67 -(void) Touchesbegan: (Nsset *) touches withevent: (uievent *) event{70 [self dropaanimation];71}72 @end
This link from http://www.cnblogs.com/chenhongios/p/4853970.html
iOS Animation tutorials