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!