Core animation is a very powerful calayer (not UIView) animation process that works across Mac OS X and iOS platforms Api,core Animation animation execution is done in the background and does not block the main thread.
Core animation inheritance Structure
Core animation Inheritance Structure Note: Virtual classes in core animations are not available and should use real classes in their subclasses. Steps for using Core animation
If it is a previous version of Xcode6, to import the <QuartzCore/QuartzCore.h> framework (there is no coreanimation frame)
Development steps:
First you have to have Calayer(because Coreanimation is a function of Calayer)
Initializes a Caanimation object and sets some animation-related properties
By calling the Calayer addAnimation:forKey:
method, add the Caanimation object to the Calayer so that you can start the animation
removeAnimationForKey:
You can stop the animation in Calayer by calling the Calayer method
Some of the properties in Caanimation:
duration
: Duration of animation
repeatCount
: Repeat number, infinite loop can be set huge_valf or maxfloat
repeatDuration
: Repeat Time
removedOnCompletion
: The default is Yes, 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*
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 to control the rhythm of animation operation
delegate
: Animation agent
fillMode
Determines the behavior of the current object during a non-active time period. (If you want Fillmode to work, it's 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, the end of the animation, the layer will revert to the previous state
kCAFillModeForwards
When the animation finishes, the layer retains the last state of the animation
Kcafillmodebackwards before the animation begins, just 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 remains the last state of the animation after the animation finishes.
CAMediaTimingFunction
: Speed control function
kCAMediaTimingFunctionLinear
(linear): constant speed, gives you a relatively static feeling
kCAMediaTimingFunctionEaseIn
(progressive): Animation slowly enters, then accelerates to leave
kCAMediaTimingFunctionEaseOut
(Fade Out): Animation enters at full speed, then slows down to the destination
kCAMediaTimingFunctionEaseInEaseOut
(Gradual fade Out): The animation slowly enters, the middle accelerates, then slows down to reach the destination. This is the default animation behavior.
Caanimation Proxy method
Caanimation defines the proxy method in the taxonomy. is to add the classification to NSObject, so any object, become caanimation agent, all can.
Called when the animation starts
- (void)animationDidStart:(CAAnimation *)anim;
Called when the animation stops
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag;
Pause and resume animations on Calayer
Time out
-(void)pauseLayer:(CALayer*)layer { CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil]; // 让CALayer的时间停止走动 layer.speed = 0.0; // 让CALayer的时间停留在pausedTime这个时刻 layer.timeOffset = pausedTime; }
Recovery
-(void)resumeLayer:(CALayer*)layer { CFTimeInterval pausedTime = layer.timeOffset; // 1. 让CALayer的时间继续行走 layer.speed = 1.0; // 2. 取消上次记录的停留时刻 layer.timeOffset = 0.0; // 3. 取消上次设置的时间 layer.beginTime = 0.0; // 4. 计算暂停的时间(这里也可以用CACurrentMediaTime()-pausedTime) CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime; // 5. 设置相对于父坐标系的开始时间(往后退timeSincePause) layer.beginTime = timeSincePause; }
cabasicanimation--Basic Animations
cakeyframeanimation--Key-Frame animations
Keyframe animation, also capropertyanimation subclass, differs from Cabasicanimation:
Cabasicanimation can only change from one numeric value (Fromvalue) to another (Tovalue), and Cakeyframeanimation saves the values with a Nsarray
Property Description:
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), in turn
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, then values will be ignored
keyTimes
: You can specify a corresponding point in time for the corresponding keyframe, with a value range of 0 to 1.0,keytimes each time value corresponds to 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, is a CAAnimation
subclass that can hold a set of animated objects, after the object is joined to the CAAnimationGroup
layer, all animation objects in the group can concurrently run
Property Description:
animations
: A nsarray used to hold a set of animated objects
By default, a set of animated objects runs concurrently, 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 CAAnimation
subclass that is used to animate transitions, providing the ability to animate layers to move out of the screen and into the screen. 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
Animation properties:
type
: Animation Transition Type
subtype
: Animation transition Direction
startProgress
: Start of animation (percentage of overall animation)
endProgress
: End of animation (percentage of overall animation)
1. 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 animation
view
: A view that requires a transition animation
options
: Type of transition animation
animations
: Place code that changes the properties of the view in this block
completion
: This block is automatically called after the animation is finished.
2. 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 code that changes the properties of the view in this block
completion
: This block is automatically called after the animation is finished.
3. Write your own transitions
- To create a transition animation:
[CATransition animation]
- Set Animation property values
- Add to a layer that requires transition animations
[layer addAnimation:animation forKey:nil]
Type of transition animation (NSString *type)
fade
: Cross-fade transitions
push
: New view launches old view
moveIn
: The new view is moved above the old view
reveal
: Moves the old view away, showing the new view below
cube
: Cube Rollover Effect
oglFlip
: Flip effect up or down
suckEffect
: Shrinkage effect, like a piece of cloth being pumped away
rippleEffect
: Drop Effect
pageCurl
: Page UP effect
pageUnCurl
: Page DOWN effect
cameraIrisHollowOpen
: Camera lens Open effect
cameraIrisHollowClos
: Camera lens off effect
Direction of transition Animation (NSString *subtype)
- Start in One Direction:,,
fromLeft
fromRight
fromTop
,fromBottom
Coreanimation in the CALayer1. Careplicatorlayer: Copying layers
As the name implies, duplicate layers are used to replicate. It copies its own sublayers, along with the animations on the child layer.
2. Cashapelayer: Shape layer
Layers that draw content based on the shape
Property Description:
path
: Describes the path to a shape. The path is closed by default and then populated.
fillColor
: The color of the fill
strokeColor
: The color of the stroke (if you want to just stroke it, set FillColor to Clearcolor.)
strokeStart
: The scale "0-1" at which the stroke begins
strokeEnd
: The ratio "0-1" for ending strokes
3. Cagradientlayer: Gradient Layer
With this layer, you can make the color gradient
Property Description:
colors
: Save all gradient colors, inside is cgcolorref, remember to use ID, let the compiler think that the array is OC object.
locations
: Save the position of all gradients "0-1"
startPoint
: Start gradient point "0-1"
endPoint
: End gradient of point "0-1"
At last:
The core animation shows us just an illusion that the frame, bounds, and position of the layer will not change after the animation has finished.
UIView encapsulated animations will make it true to modify some of the properties of the view.
Website API:Core Animation
Ios-core Animation (Core animation)