Draw a line on a view and animate it so that you can encapsulate three methods:
/**
* Dash Tool
*
* @param number of Linearray segments nsvalue type default first point is start
* @param Time Dash
* @param strokecolor line segment Color
*/
-(void) Axcbaseaniamtionwithlinepointarray: (nsarray <nsvalue *> *) Linearray time: ( cgfloat ) Time Strokecolor: (uicolor *) strokecolor{
if (Linearray. Count <= 1) {
if (_axcbaseprintlog) {
NSLog(@ "%@:\n your array object is less than one and cannot be crossed !") ,self);
}
return;
}
if (_axcbaseprintlog) {
NSLog(@ "%@:\n is currently underlined \ t method name:axcbaseaniamtionwithlinepointarray\t start :%@\t Dash time :%.2f, color :%@\n ",self,nsstringfromcgpoint([linearray[0] Cgpointvalue]), time,strokecolor);
}
uibezierpath *_path=[uibezierpath bezierpath];
cgpoint point1 = [linearray[0] cgpointvalue];
[_path movetopoint:p oint1];
for (int i = 1; i < Linearray. Count; i + +) {
[_path addlinetopoint: [linearray[i] cgpointvalue];
if (_axcbaseprintlog) {
NSLog(@ "%@: traverse Dash point (%d):%@\n",self, i + 1,nsstringfromcgpoint([ Linearray[i] cgpointvalue]);
}
}
cashapelayer *shapelayer=[cashapelayer layer];
Shapelayer. path=_path. Cgpath;
Shapelayer. fillcolor=[uicolor clearcolor]. Cgcolor; Fill Color
Shapelayer. strokecolor=strokecolor. Cgcolor; border color
[self. View. Layer addsublayer: Shapelayer];
// animation
cabasicanimation *pathaniamtion = [cabasicanimation animationwithkeypath:@ " Strokeend "];
// time
Pathaniamtion. duration = time;
Pathaniamtion. timingfunction = [camediatimingfunction functionwithname: Kcamediatimingfunctioneaseineaseout];
Pathaniamtion. fromvalue = [nsnumber numberwithfloat:0.0f];
// What percentage of the dash
Pathaniamtion. tovalue = [nsnumber numberwithfloat:1];
Pathaniamtion. autoreverses = NO;
[Shapelayer addanimation:p athaniamtion forkey:nil];
}
/**
* Compass Tool
*
* @param Center Point
* @param radius radius
* @param startangle start Angle
* @param endangle End Angle
* @param clockwise is clockwise
* @param Time
* @param strokecolor Color
*/
-(void) Axcbaseaniamtionarcwithcenter: (cgpoint ) Center
Radius: (cgfloat ) Radius
StartAngle: (cgfloat ) startangle
Endangle: (cgfloat ) endangle
Clockwise: (BOOL ) clockwise
Time: (cgfloat ) time
Strokecolor: (uicolor *) strokecolor{
uibezierpath *_path=[uibezierpath bezierpath];
[_path addarcwithcenter: Center radius: Radius startangle: startangle endangle : Endangle clockwise: clockwise];
cashapelayer *shapelayer=[cashapelayer layer];
Shapelayer. path=_path. Cgpath;
Shapelayer. fillcolor=[uicolor clearcolor]. Cgcolor; Fill Color
Shapelayer. strokecolor=strokecolor. Cgcolor; border color
[self. View. Layer addsublayer: Shapelayer];
// animation
cabasicanimation *pathaniamtion = [cabasicanimation animationwithkeypath:@ "Strokeend" ];
// time
Pathaniamtion. duration = time;
Pathaniamtion. timingfunction = [camediatimingfunction functionwithname: Kcamediatimingfunctioneaseineaseout];
Pathaniamtion. fromvalue = [nsnumber numberwithfloat:0.0f];
// What percentage of the dash
Pathaniamtion. tovalue = [nsnumber numberwithfloat:1];
Pathaniamtion. autoreverses = NO;
[Shapelayer addanimation:p athaniamtion forkey:nil];
}
/**
* Clear all dashes
*/
-(void) axcbaseclearallshapelayer{
if (_axcbaseprintlog) {
NSLog(@ "%@:\n current execution clears all dashes on the interface !") ,self);
}
nsarray *shapelayerarray = self. View. Layer. Sublayers;
for (int i = 0; i < Shapelayerarray. Count; i + +) {
if ([shapelayerarray[i] iskindofclass: [cashapelayer class]]) {
[Shapelayerarray[i] removefromsuperlayer];
}
}
}
"AXC" Simple linear animation drawing