iOS Ui--cashapelayer

Source: Internet
Author: User

Content outline:

    1. Cashapelayer Introduction
    2. The relationship between Bezier curve and Cashapelayer
    3. Strokestart and Strokeend animations
    4. 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

      • Value: Cgcolor Object
    • 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
  • 1, set the fillcolor of Shapelayer to transparent background
  • 2. Set the value of the line width (linewidth)
  • 3. Set the color of the line
  • 4, set the Strokestart value to 0, and then let the Strokeend value change trigger the implicit animation

  • Class: Cashapelayer

    • Property:

      • strokestart
      • strokeend
        • Note: The value of strokeend must be greater than Strokestart
        • Scope: (0~1)
       processing method: Shapelay Er.strokestart = Valueone < valuetwo  Valueone .strokestart = Valueone > valuetwo  Valueone       
    • Property:

      • LineWidth the width of the line
      • Strokecolor color of lines
        • Value: Cgcolor
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

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.