Layer time-level relationship time and layer-level relationship
Each animation and layer has its own hierarchical concept in terms of time, which is measured relative to its father. Adjusting the Time of the layer will affect the animation of the layer itself and the child layer, but will not affect the parent layer.
PairCALayer
OrCAGroupAnimation
Adjustmentduration
AndrepeatCount
/repeatDuration
Attributes do not affect the sub-animation. HoweverbeginTime
,timeOffset
Andspeed
Attributes will affect the sub-animation.
Global time and local time
The system provides a functionCACurrentMediaTime
To obtainMachTime, that is, absolute time. It is actually the number of seconds since the last start of the device. All processes on the device are global. It can be used as a reference for animation. However, this time will be paused during sleep.
EachCALayer
AndCAAnimation
Both have the concept of local time. Is based on the parent layer/animation hierarchybeginTime
,timeOffset
Andspeed
Attribute calculation.
- (CFTimeInterval)convertTime:(CFTimeInterval)t fromLayer:(CALayer *)l; - (CFTimeInterval)convertTime:(CFTimeInterval)t toLayer:(CALayer *)l;
After the pause or backward turn quickforward animation is added to the layer, it cannot be modified.
AddCAAnimation
In fact, an unchangeable copy is made to the animation object. Therefore, changing the attributes of the original animation object does not affect the real animation. Instead, use-animationForKey:
You can return the correct animation object to retrieve ongoing layers, but modifying its attributes will throw an exception.
- Pause
If you setspeed
If it is set to 0, it pauses any animation added to the layer.
- Reverse
Setspeed
A negative value will be converted back to the animation.
- Fast forward
Setspeed
More than 1.0 will be fast forward