Bézier curves & cashapelayer & Stroke Animations

Source: Internet
Author: User
Tags transparent color

Reprinted from: http://46aae4d1e2371e4aa769798941cef698.devproxy.yunshipei.com/qiaoqiaoqiao2014/article/details/46928787

1.CAShapeLayer Introduction

1.1CAShapeLayer inherits from Calayer and can use all the property values of Calayer;

1.2CAShapeLayer requires Bézier curves to be used in order to make sense (that is, to have effects)

1.3 Using Cashapelayer (belonging to coreanimation) and Bezier curves can be implemented in the DrawRect of the view (inherited from the Coregraphics walk is the CPU, the performance of a large consumption) method to draw some desired graphics

1.4CAShapeLayer animation rendering is submitted directly to the GPU of the phone, which is highly efficient compared to the DrawRect method of view, and can greatly optimize memory usage

2.CAShapeLayer use

2.1 Code Show



1. The relationship between Bezier curves and Cashapelayer

1.1CAShapeLayer requires a shape to take effect, a Bezier curve can create a vector-based path, which in turn provides a path to Cashapelayer, and the path is closed-loop.

The 1.2 Bezier curve is the path of the Cashapelayer, whose path is a closed-loop, end-to-end curve.

2. Practical Application

2.2 Draw Ellipse



2.2 Draw a rectangle, the method of drawing a circle is consistent with the top, but the method called when drawing is inconsistent.

3. Note: Bezier curves and Cashapelayer frame values do not interfere, Bezier is only to be placed on the Cashapelayer layer, So the frame.size of Cashapelayer cannot be less than the frame.size of the Bezier curve,Maskstobounds is a property of Cashapelayer, The path that prohibits Bezier curves extends beyond the frame range of Cashapelayer.

4.StrokeStart and the use of strokeend

4.1 Usage steps:

4.1.1 Set the FillColor of shapelayer into a transparent color

4.1.2 Set the width of the edge line

4.1.3 Set the color of the edge line

4.1.4 Set the Strokestart value to 0 to change the value of strokeend, triggering an implicit animation

4.1.5 uses a timer to make it change

4.2 Case Application


, this is the gradient sliding, similar to the buckle landing of the waiting rotation view, you can go to my blog resources to download the demo Oh.


Bézier curves & cashapelayer & Stroke Animations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.