"AXC" Simple linear animation drawing

Source: Internet
Author: User

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

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.