Coreanimation Introduction
Core animation is a very powerful set of animation processing APIs that can be used to make very flashy animations, often with less effort! Core Animation is the parent of all animated objects and is responsible for controlling the duration and speed of the animation, an abstract class that cannot be used directly, and should use its specific subclasses
Using it requires adding quartzcore.framework and introducing the corresponding frame <QuartzCore/QuartzCore.h>
Description of the property: Property Description: (Red represents a property from the Camediatiming protocol)
Duration: Duration of animation
RepeatCount: Number of repetitions, infinite loop can be set huge_valf or maxfloat repeatduration: Repeat time removedoncompletion: Yes by default , which is removed from the layer after the animation has finished executing, and the drawing reverts to the state before the animation was executed. If you want the layer to remain displayed after the animation has been executed, set 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 or after the animation 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 run delegate: Animation Agent Fillmode Property value (to want F Illmode valid, preferably 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, Layer reverts to previous state kcafillmodeforwards when the animation finishes, the layer retains the final state of the animation &NBSP;KCAFILLMODEBACKW Ards before the animation begins, simply add the animation to a layer,layer and immediately enter the initial state of the animation and wait for the animation to begin. 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 retains the final state speed control function (camediatimingfunction) 1 after the animation finishes. Kcamediatimingfunctionlinear (linear): constant speed, gives you a relatively static feel 2.kCAMediaTimingFunctionEaseIn (progressive): Animation slowly enters, then accelerates to leave 3.kCAMediaTimingFunctionEaseOut (Fade Out): The animation enters at full speed and then slows down to the destination 4.kCAMediaTimingFunctionEaseInEaseOut (gradual fade Out): Animation slow entry, intermediate acceleration, Then decelerate to reach the destination. This is the default animation behavior.
Development steps:
1. Initialize an Animated object (Caanimation) and set some animation-related properties.
2, Calayer animation properties can be achieved through caanimation, including: opacity, position, transform, bounds, contents, etc. (You can search in the API documentation: Calayer Animatable Properties)
3. Add an animated object to the layer (Calayer) to start the animation
4, by calling Calayer Addanimation:forkey add animation to the layer (Calayer), so that the animation can be triggered. You can stop an animation in a layer by calling Removeanimationforkey
5, the Core animation animation execution process is in the background operation, does not block the main thread
Inheritance structure of coreanimation
Animation pause
1 #pragmaMark pauses the Calayer animation2-(void) Pauselayer: (calayer*) Layer3 {4Cftimeinterval Pausedtime =[Layer Converttime:cacurrentmediatime () Fromlayer:nil];5 6 //let Calayer's time stop moving.7Layer.speed =0.0;8 //let Calayer time stay in pausedtime this moment9Layer.timeoffset =Pausedtime;Ten}
Recovery of animations
1 #pragmaMark restores Calayer's animations2-(void) Resumelayer: (calayer*) Layer3 {4Cftimeinterval Pausedtime =Layer.timeoffset;5 //1. Let the calayer time continue to walk6Layer.speed =1.0;7 //2. Cancel last recorded time of stay8Layer.timeoffset =0.0;9 //3. Cancel the last set timeTenLayer.begintime =0.0; One //4. Calculate the time of the Pause (Cacurrentmediatime () can also be used here-pausedtime) ACftimeinterval timesincepause = [Layer Converttime:cacurrentmediatime () Fromlayer:nil]-Pausedtime; - //5. Set the start time relative to the parent coordinate system (go back to Timesincepause) -Layer.begintime =Timesincepause; the} Capropertyanimation is a subclass of Caanimation, also an abstract class, to create an animated object, you should use its two subclasses: Cabasicanimationcakeyframeanimation Property Description: KeyPath: By specifying a property name of Calayer of KeyPath (NSString type), and the value of this property of Calayer is modified 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
cabasicanimation--Basic Animations
The basic animation is a subclass of Capropertyanimation property Description: Fromvalue:keypath The initial value of the corresponding property Tovalue:keypath the end value of the corresponding property animation process description: As the animation progresses, Within the duration of duration, keypath the value of the corresponding property changes from Fromvalue to Tovaluekeypath content is Calayer animated animatable property if fillmode= Kcafillmodeforwards is removedoncomletion=no at the same time, after the animation finishes, the layer remains displayed after the animation is executed. But in essence, the property value of the layer is still the initial value before the animation is executed, and it is not really changed. Keyframe animation, also a subclass of Capropertyanimation, differs from cabasicanimation in that cabasicanimation can only change from one numeric value (Fromvalue) to another (Tovalue). Instead, Cakeyframeanimation uses a nsarray to hold these numeric property descriptions: Values: 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) path: You can set a cgpathref, Cgmutablepathref, and let the layer move along the path trajectory. Path only works on Calayer's anchorpoint and position. If path is set, values will be ignored Keytimes: You can specify a corresponding point in time for the corresponding keyframe, with a value range of 0 through 1.0,keytimes for each frame in values. If Keytimes is not set, the time of each keyframe is equally divided cabasicanimation can be seen as a cakeyframeanimation with only 2 keyframes Caanimationgroup Animation Group Animation group, which is a subclass of Caanimation, can save a set of animated objects, after the Caanimationgroup object is added to the layer, all animated objects in the group can concurrently run property descriptions: animations: Nsarray used to hold a set of animated objects by default , a set of animated objects is run at the same time, or you can change the start time of an animation by setting the BeginTime property of the animated object Transition Animation-- Catransition Catransition is a subclass of caanimation that is used to animate transitions and animate layers to move out of the screen and into the screen. iOS has a little less transition animation than Mac OS x Uinavigationcontroller is an animated effect that pushes the view of a controller into the screen by catransition: type: Animation transition type subtype: Animation transition Direction STA Rtprogress: Start of Animation (percentage of overall animation) Endprogress: End of Animation (percentage of overall animation) Transitions Animation Transition Effect Using the UIView animation function for transition animations--single view + (void) Transitionwithview: (UIView *) View Duration: (nstimeinterval) Duration options: (uiviewanimationoptions) Options animations: (void (^) (void)) animations completion: (void (^) (BOOL finished)) completion; Parameter Description: Duration: Duration of the animation view: Views that require transition animations options: Type of transition animation animations: Place code that changes the properties of the view in this block completion: After the animation is over, will automatically call this block animating transitions using the UIView animation function--dual view + (void) Transitionfromview: (UIView *) Fromview Toview: (UIView *) Toview Duration: (nstimeinterval) Duration options: ( uiviewanimationoptions) Options Completion: (void (^) (BOOL finished)) completion; Parameter Description: Duration: Duration of animation options: Type of transition animation animations: Place the code that changes the View property in this block completion: After the animation is finished, the block is automatically called Cadisplaylink Cadisplaylink is a clock mechanism triggered by screen refresh frequency, approximately 60 times per second Cadisplaylink is a timer that keeps the drawing code in sync with the refresh rate of the view, and Nstimer does not ensure the exact time at which the timer is actually triggered How to: Define a cadisplaylink and develop a trigger call method to add a display link to the main run loop queue
IOS Core Animations