Introductionquestion one: What are core animations (cores Animation)? Core animation is a very powerful animation processing API that uses it to make very flashy animations, often with less effort, and uses it to first add quartzcore.framework and introduce a corresponding framework <quartzcore/ Many of the properties in Quartzcore.h> Calayer can be animated by caanimation, including: opacity, position, transform, bounds, contents, etc. ( You can search in the API documentation: Calayer animatable Properties)• Add animation to the layer (Calayer) by calling Calayer's Addanimation:forkey to trigger the animation. You can stop an animation in a layer by calling Removeanimationforkey Core Animation's animation execution process isBackground OperationOfdoes not block the main thread question two: development steps① Initializes an animated object (caanimation) and sets some animation-related properties② add an animated object to the layer (Calayer) to start the animation ①caanimationquestion one: brief
The parent class of all animated objects, which controls the duration and speed of the animation, is an abstract class that cannot be used directly and should use its specific subclassescaanimation Inheritance Structure
Note : The black dashed line in indicates "inherit" a class, the red dashed line means "obey" a protocol
problem Two: attribute parsingRed represents a property from the Camediatiming protocol ODuration: Duration of animation øRepeatCount: Number of repetitions of animation ORepeatDuration: The repetition time of the animation øremovedoncompletion: By default, yes, which is removed from the layer after the animation has finished executing, and the shape reverts to the state before the animation was executed. If you want the layer to remain displayed after the animation has been executed, set it to no, but also set Fillmode to KcafillmodeforwardsøFillmode: Determines the behavior of the current object during a non-active time period. For example, before the animation starts, after the animation is finished ØBeginTime: Can be used to set the animation delay execution time, if you want to delay 2s, set to Cacurrentmediatime () +2,cacurrentmediatime () is the current time of the layer øtimingfunction: speed control function, Control the rhythm of animation ødelegate: Animation agentPS: Benefits
speed control function (camediatimingfunction)1. Kcamediatimingfunctionlinear (linear): constant speed, gives you a relatively static feeling2. Kcamediatimingfunctioneasein (Progressive): Animation slowly enters, then accelerates to leave3. Kcamediatimingfunctioneaseout (Fade Out): Animation enters at full speed, then slows down to the destination4. Kcamediatimingfunctioneaseineaseout (Gradual fade Out): The animation slowly enters, the middle accelerates, and then slows down to reach the destination. This is the default animation behavior. Caanimation defines the proxy method in the classification@interfaceNSObject (caanimationdelegate)- (void) Animationdidstart: (Caanimation *) Anim;- (void) Animationdidstop: (Caanimation *) Anim finished: (BOOL) flag;@endFillmode Property value (for Fillmode to be valid, it is best to set removedoncompletion=No)kcafillmoderemoved This is the default value, that is, when the animation starts and after the end of the animation, the animation has no effect on the layer, after the end of the animation, the layer will revert to the previous state? Kcafillmodeforwards When the animation is finished, the layer will remain the last state of the animation?
Kcafillmodebackwards Before the animation begins, you simply add the animation to a layer,layer and immediately enter the initial state of the animation and wait for the animation to begin. You can set the test code like this, A delay of 5 seconds is performed when an animation is added to a layer. Then you will find that when the animation is not started, as long as the animation is added to the Layer,layer will be in the initial state of animation? Kcafillmodeboth This is actually the composition of the above two. Before the animation joins, the layer is in the initial state of the animation, and the layer remains animated on the last shape of the animation after the animation is finished Calayer and resumed.//t-active The local time of the locals Times layer//Tp-parent the time of the parent layer on a layer//Time Conversion formula for parent layer and layer local//t = (tp-begintime) * speed + Timeoffset//beginTime = TP-(t-timeoffset)/speed#pragmaMark pauses the Calayer animation-(void) Pauselayer: (calayer*) layer{Cftimeinterval pausedtime=[Layer Converttime:cacurrentmediatime () Fromlayer:nil]; Layer.speed=0.0;//let Calayer's time stop moving.Layer.timeoffset = Pausedtime;//let Calayer time stay in pausedtime this moment}#pragmaMark recovers Calayer's animations-(void) Resumelayer: (calayer*) layer{Cftimeinterval pausedtime=Layer.timeoffset; Layer.speed=1.0;//Let the calayer time continue to walkLayer.timeoffset =0.0;//cancels the last record's dwell timeLayer.begintime =0.0;//Cancel the last set time//calculate the time to pause (Cacurrentmediatime ()-pausedtime is the same here)Cftimeinterval timesincepause = [Layer Converttime:cacurrentmediatime () Fromlayer:nil]-Pausedtime; //sets the start time relative to the parent coordinate system (backward timesincepause)Layer.begintime =Timesincepause;}
②capropertyanimation (Property Animations)question one: brief
is a subclass of Caanimation and an abstract class, to create an animated object, you should use its two subclasses:cabasicanimationAndcakeyframeanimationproblem Two: attribute parsing
KeyPath: By specifying the Calayer property name as KeyPath (nsstring type), you only need to modify the value of the Calayer property to achieve the corresponding animation effect. For example, if you specify @ "position" as KeyPath, the value of the position property of the Calayer is modified to achieve the animated effect of panning③cabasicanimationquestion one: brief
It's a subclass of Capropertyanimation.
problem Two: attribute parsing Fromvalue: KeyPath The initial value of the corresponding propertyTovalue: KeyPath the end value of the corresponding property • As the animation progresses, the value of the keypath corresponding property is gradually changed from Fromvalue to Tovalue for the duration of the duration length.Note: If fillmode=kcafillmodeforwards and Removedoncomletion=no, After the animation finishes, the layer remains displayed after the animation is executed . essentially, the property value of a layer is the initial value of the animation before it is executed and is not really changed. For example,Calayer's position initial value is (0,0), Cabasicanimation's Fromvalue is (10,10), Tovalue is (100,100) ,Although the layer remains at (100,100) This position after the animation finishes, the position of the actual layer is still (0,0)PS: Benefits
//Panning AnimationsCabasicanimation *anim = [cabasicanimation animationwithkeypath:@"position"];anim.duration=1;//animation lasts 1 seconds//because Cgpoint is a struct, it is packaged as an OC object with NsvalueAnim.fromvalue = [Nsvalue valuewithcgpoint:cgpointmake ( -, -)];anim.tovalue= [Nsvalue Valuewithcgpoint:cgpointmake ( -, -)]; [Layer Addanimation:anim Forkey:@"Myanim"];//the corresponding animated object can be retrieved by Myanim, for example, to cancel the animation halfway//Zoom AnimationCabasicanimation *anim = [cabasicanimation animationwithkeypath:@"Transform"];//No setting fromvalue indicates the current state as the initial value//width is twice times the original, height is 1.5 times times the originalAnim.tovalue = [Nsvalue Valuewithcatransform3d:catransform3dmakescale (2,1.5,1)];anim.duration=1; [Layer Addanimation:anim Forkey:nil];//Rotate AnimationCabasicanimation *anim = [cabasicanimation animationwithkeypath:@"Transform"];//here is a vector (1, 1, 0) for the axis, rotated Π/2 radians (90°)//If you just spin the phone plane, set the vector to (0, 0, 1), which is the z axisAnim.tovalue = [Nsvalue valuewithcatransform3d:catransform3dmakerotation (M_pi_2,1,1,0)];anim.duration=1; [Layer Addanimation:anim Forkey:nil];
④cakeyframeanimation (Key-Frame animations)question one: brief
• is a subclass of Capropertyanimation • With Cabasicanimation'sdifferenceis: Cakeyframeanimation uses one nsarray to hold multiple attribute elements, whereas cabasicanimation can only change from one numeric value (Fromvalue) to another (Tovalue)ps:cabasicanimationcan be seen asa maximum of 2 keyframesOfcakeyframeanimation
problem Two: attribute parsingvalues:The Nsarray object above. The elements inside are called "keyframes" (keyframe). The animated object displays each keyframe in the values array in the specified time (duration), in turnPath:You can set a cgpathref\cgmutablepathref so that the layer moves along the path. Path only works on Calayer's anchorpoint and position.If you set the path, the values will be ignored Keytimes:You can specify a corresponding point in time for the corresponding keyframe, and each time value in the range of 0 to 1.0,keytimes corresponds to each frame in values. When the keytimes is not set, the time of each keyframe is equally divided.PS: Benefits
There is also a very important parameter in the Keyframe animation, which isCalculationmode (calculation mode).
• The main target is the case of one block punctuation for each frame, which is the animation of anchorpoint and position.
• When there are multiple discrete points in a planar coordinate system, they can be discrete, or they can be interpolated after straight lines, or they can be interpolated using a sleek curve.
•CalculationmodeCurrently offers the followingseveral modes:Kcaanimationlinear ///Calculationmode default value, indicating that when keyframes are block punctuation, the direct straight line between keyframes is interpolated to calculate the interpolation value .
Kcaanimationdiscrete// discrete , is not the interpolation calculation, all the key frames are displayed directly;
? kcaanimationpaced//Make the animation evenly, not set by Keytimes or split the time by key frame, Keytimes and timingfunctions are invalid at this time;
? kcaanimationcubic//The key frame for the block punctuation key frame for the smooth curve after the interpolation calculation , the main purpose here is to make the running trajectory become smooth;
kcaanimationcubicpaced//See this name to know and Kcaanimationcubic have a certain connection, in fact, is on the basis of Kcaanimationcubic make the animation run evenly, is the system time within the same distance movement, Keytimes and timingfunctions are not valid at this time.
⑤caanimationgroup ( concurrent Animation group )question one: brief
caanimation, you can save a group of animated objects, and after the Caanimationgroup object is added to the layer, all the animated objects in the group canConcurrent runs concurrently
problem Two: attribute parsing Animations: A nsarray used to hold a set of animated objectsPS: • By default, a set of animated objects is run concurrently, or you canSet Animated ObjectsOfBeginTime property to change the start time of the animation ⑥catransition ( transition )question one: brief
Subclasses of the caanimation,used to animate transitions.To provide the layer withmove out of the screenAndmove into screenAnimation effect. iOS has less transition animations than Mac OS X
•Uinavigationcontroller is the animation effect of pushing the controller's view into the screen via Catransition
problem Two: attribute parsing •Type:Animation transition Type ·Subtype:Animation transition Direction ·startprogress: Start of animation (% of overall animation) ·endprogress:Animation end Point (percentage of overall animation)
/* Transition effect fade//Crossfade Transition (transition direction not supported) Kcatransitionfade push//New view eject old view Kcatransitionpush Movein//New view move to Old view
kcatransitionmovein
Reveal//Move the old view away to show the new view below Kcatransitionreveal
Cube//Cube Rollover effect oglflip//up/down flip effect
Suckeffect//shrinkage effect, such as a piece of cloth is pumped away (not support transition direction)
Rippleeffect//Drip effect (transition direction not supported)
Pagecurl//Page UP effect
Pageuncurl//Page DOWN effect
Camerairishollowopen//Camera lens open effect (transition direction not supported)
Camerairishollowclose//Camera lens Close effect (no transition direction is supported)
*/
011-ios Core animations (core Animation)