iOS animations use Cagradientlayer for animations

Source: Internet
Author: User

Look at the film first.

Analysis steps:

1. Draw a square layer first, if:

The code is as follows:

Cagradientlayer *colorlayer =[Cagradientlayer layer]; Colorlayer.backgroundcolor=[Uicolor Bluecolor].    Cgcolor; Colorlayer.frame= (CGRect) {Cgpointzero, Cgsizemake ( $, $)}; Colorlayer.position=Self.view.center;        [Self.view.layer Addsublayer:colorlayer]; //Color DistributionColorlayer.colors = @[(__bridgeID) [Uicolor Redcolor]. Cgcolor, (__bridgeID) [Uicolor Whitecolor]. Cgcolor, (__bridgeID) [Uicolor Redcolor].    Cgcolor]; //The starting position is set to beyond the interface so the default is no effectColorlayer.locations = @[@ (-0.2), @(-0.1), @(0)]; //starting pointColorlayer.startpoint = Cgpointmake (0,0); //End PointColorlayer.endpoint = Cgpointmake (1,0);

2. Set the grating slide effect

The code is as follows:

 cabasicanimation* Fadeanim = [cabasicanimation animationwithkeypath:@ "    Span style= "COLOR: #800000" >locations   " ];  //  start position left outside  fadeanim.fromvalue = @[ @ (-0.2 ) @ (-0.1 ), @ ( 0      //  end position right outside  Fadeanim.tovalue = @[@ ( 1.0 ) @ (1.1 ), @ ( 1.2      = 1.5  ; [Colorlayer Addanimation:fadeanim Forkey:nil];  

3. Set the mask mask for the layer to show only the circles

uibezierpath* Bezierpath = [Uibezierpath bezierpathwitharccenter:cgpointmake (0,0) Radius: theStartangle:degrees (0) Endangle:degrees ( the) Clockwise:yes]; Cashapelayer*layer =[Cashapelayer layer]; Layer.path=Bezierpath.cgpath; //locationLayer.position = Cgpointmake (102, -); //fill color is transparentLayer.fillcolor =[Uicolor Clearcolor].    Cgcolor; //border color is redLayer.strokecolor =[Uicolor Redcolor].    Cgcolor; //set the matte, which displays the contents of the matteColorlayer.mask = layer;

This completes the final effect.

iOS animations use Cagradientlayer for 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.