Content outline:
- Cashapelayer Introduction
- The relationship between Bezier curve and Cashapelayer
- Strokestart and Strokeend animations
- Use Cashapelayer to achieve progress bar effects and more complex effects
1, Cashapelayer Introduction
- 1, cashapelayer inherit from Calayer, you can use all the property values of Calayer
- 2. Cashapelayer needs to be used in conjunction with Bezier curves to make sense
- 3, using Cashapelayer and Bezier curve can be implemented in the DrawRect method of the view to draw some of the desired graphics
- 4, Cashapelayer belongs to the coreanimation frame, its animation rendering directly to the mobile phone GPU, compared to the view of the DrawRect method using CPU rendering, it is very efficient, can greatly optimize memory usage.
- Personal experience: You can override DrawRect in UIView subclasses to achieve a progress bar effect, but UIView's drawrect is implemented with CPU rendering, and cashapelayer is more efficient because it uses GPU rendering.
Effect: Although it is said that directly changing the created Calayer and its subclasses will trigger the implicit animation, but directly change the value of the Cashapelayer path, the change process does not have the effect of gradient movement, So here we need to use the core animation cabasicanimation to help achieve, not using the core animation verification effect in the back of the "4, with Cashapelayer to achieve progress bar effect, and more complex effect" verified. 2. The relationship between Bezier curve and Cashapelayer
- 1, Cashapelayer has shape this word, as the name implies, it needs a shape to take effect
- 2. Bezier curves can create vector-based paths
- 3, Bezier curve to Cashapelayer provide a path, cashapelayer in the provided path to render, the path will be closed loop, so the path is drawn out shape
4, the Bezier curve for Cashapelayer as path, its path is a closed-loop curve of the end-to-end, even if the Bezier curve is not a closed-loop curve
Figure 2.png
How to establish the relationship between Bezier curves and Cashapelayer:
- Class: Cashapelayer
Properties: Path
- Value: Can be a Bézier curve object
uibezierpath * Circle = [uibezierpath bezierpathwithovalinrect:cgrectmake (0,0,< Span class= "token number" >200,100) ];shape .path = circle
Properties: FillColor Modifying the fill color of a Bezier curve
Property: Masktobounds
- Value: YES causes parts that exceed cashapelayer to not be displayed
The first order Bezier curve quadratic Bezier curve Sanche Besel curve Shirer Besel curve five-order Bezier curve then the relationship between Bezier curve and Cashapelayer is directly represented by code: 3, Strokestart and strokeend animation
Then in order to achieve the effect of the circular progress bar: The effect is: The above Strokestart also set, but note: Strokestart must be less than strokeend, otherwise will not draw the case.
4, using Cashapelayer to achieve circular progress bar effect, and more complex synthesis of animation effect
Circular progress bar animation. gif
Source: Circleprogress in the circleprogress source code
You need to use the core animation to directly change the result of path without the desired gradient process:
Comprehensive sample source code see: Https://github.com/HeYang123456789/UIView
If Fillcolors is not set to [Uicolor Clearcolor]. The Cgcolor will have this effect:
Reprint site: http://www.cnblogs.com/goodboy-heyang/p/5185575.html
iOS Ui--cashapelayer