IOS Gradient Ring rotation animation Cashapelayer Cagradientlayer_ios

Source: Internet
Author: User

iOS gradient ring rotation animation Cashapelayer Cagradientlayer

Shape.gif

Demo.png

-(void) viewdidload {[Super viewdidload];

 Do no additional setup after loading the view, typically from a nib.
 Calayer *layer = [Calayer layer]; Layer.backgroundcolor = [Uicolor Redcolor]. Cgcolor;


 Ring Background layer.frame = CGRectMake (100, 100, 110, 110); Create a ring Uibezierpath *bezierpath = [Uibezierpath bezierpathwitharccenter:cgpointmake (in) radius:50 startAngle:0

 Endangle:m_pi*2 Clockwise:yes];
 Ring cover Cashapelayer *shapelayer = [Cashapelayer layer]; Shapelayer.fillcolor = [Uicolor Clearcolor].
 Cgcolor; Shapelayer.strokecolor = [Uicolor Redcolor].
 Cgcolor;
 Shapelayer.linewidth = 5;
 Shapelayer.strokestart = 0;
 Shapelayer.strokeend = 0.8;
 Shapelayer.linecap = @ "Round";
 Shapelayer.linedashphase = 0.8;

 Shapelayer.path = Bezierpath.cgpath; Color gradient Nsmutablearray *colors = [Nsmutablearray arraywithobjects: (ID) [Uicolor redcolor]. Cgcolor, (ID) [Uicolor whitecolor].
 Cgcolor, nil];
 Cagradientlayer *gradientlayer = [Cagradientlayer layer]; Gradientlayer.shadowpath = BeziErpath.cgpath;
 Gradientlayer.frame = CGRectMake (50, 50, 60, 60);
 Gradientlayer.startpoint = Cgpointmake (0, 1);
 Gradientlayer.endpoint = cgpointmake (1, 0);
 [Gradientlayer Setcolors:[nsarray arraywitharray:colors]]; [Layer Addsublayer:gradientlayer]; Set the color gradient [layer Setmask:shapelayer];

 Set the ring mask [Self.view.layer Addsublayer:layer];
 Animation cabasicanimation *scaleanimation1 = [cabasicanimation animationwithkeypath:@ "Transform.scale"];
 Scaleanimation1.fromvalue = [NSNumber numberwithfloat:1.0];
 Scaleanimation1.tovalue = [NSNumber numberwithfloat:1.5];
scaleanimation1.autoreverses = YES;
 Scaleanimation1.fillmode = Kcafillmodeforwards;

 Scaleanimation1.duration = 0.8;
 Cabasicanimation *rotationanimation2 = [cabasicanimation animationwithkeypath:@ "Transform.rotation.z"];
 Rotationanimation2.fromvalue = [NSNumber numberwithfloat:0];
 Rotationanimation2.tovalue = [NSNumber numberwithfloat:6.0*m_pi];
rotationanimation2.autoreverses = YES; Scaleanimation.fillmode = KcafillmodefOrwards;
 Rotationanimation2.repeatcount = maxfloat; Rotationanimation2.begintime = 0.8;


 Delay execution, comment out the animation will be rotationanimation2.duration = 2;
 Combined animation Caanimationgroup *groupannimation = [Caanimationgroup animation];
 Groupannimation.duration = 4;
 groupannimation.autoreverses = YES;
 Groupannimation.animations = @[scaleanimation1, RotationAnimation2];
 Groupannimation.repeatcount = maxfloat;

[Layer addanimation:groupannimation forkey:@ "groupannimation"];
 }-(void) didreceivememorywarning {[Super didreceivememorywarning];
Dispose of any of the can is recreated.
 } @end

The key place is the KeyPath setting in the initialization of the Cabasicanimation object. There are several different keypath in iOS that represent different effects:

The above is the iOS gradient Circle rotation animation data collation, follow-up continue to supplement the relevant information, thank you for your support of this site!

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.