IOS UI -- CAShapeLayer, ui -- cashapelayer
About CAShapeLayerCAShapeLayer
- 1. CAShapeLayer inherits from CALayer and can use all attribute values of CALayer.
- 2. CAShapeLayer must be used with the besell curve to make sense.
- 3. The CAShapeLayer and besserer curves can be used to draw some desired images in the drawRect method of view.
- 4. CAShapeLayer belongs to the CoreAnimation framework. Its animation rendering is directly submitted to the GPU of the mobile phone. Compared with the drawRect method of view, CAShapeLayer is highly efficient in CPU rendering, memory usage can be greatly optimized.
- Personal experience: You can override drawRect In the subclass of UIView to achieve the progress bar effect. However, drawRect of UIView is implemented by CPU rendering, while CAShapeLayer is more efficient because it uses GPU rendering.
Relationship between the beiser curve and CAShapeLayer
- 1. CAShapeLayer has the word Shape. As the name suggests, it requires a Shape to take effect.
- 2. You can create a vector-based path using the besell curve.
- 3. The beiser curve provides the path for CAShapeLayer. CAShapeLayer renders the PATH provided by CAShapeLayer, and the path is closed. Therefore, the Shape is drawn for the path.
4. The beiser curve used for CAShapeLayer is used as the path, and its path is a closed-loop curve that is connected first and end, even if the beiser curve is not a closed-loop Curve
Figure 2.png
How to establish the relationship between the beiser curve and CAShapeLayer:
- Class: CAShapeLayer
Attribute: path
- Value: it can be a beiser curve object.
UIBezierPath *circle = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0,0,200,100)];shape.path = circle.CGPath;
Attribute: fillColor: Modify the fill color of the beiser curve.
Attribute: maskToBounds
- Value: YES. The part exceeding CAShapeLayer is not displayed.
StrokeStart and strokeEnd Animation
Use CAShapeLayer to implement the Circular progress bar
Circular animation. gif
Source code: CircleProgress source code in CircleProgress
Directly changing the path results does not have an ideal gradient process, so you need to use the core Animation:
Comprehensive sample source code see: https://github.com/HeYang123456789/UIView