close
#define DEGREES_TO_RADIANS(degrees) ((pi * degrees)/ 180)
//初始化Layer
-(void)intiUIOfView
{
UIBezierPath *path=[UIBezierPath bezierPath];
CGRect rect=[UIScreen mainScreen].applicationFrame;
//開始畫圓
[path addArcWithCenter:CGPointMake(rect.size.width/2,rect.size.height/2-20) radius:100 startAngle:DEGREES_TO_RADIANS(-90)
-(void)intiUIOfView
{
UIBezierPath *path=[UIBezierPath bezierPath];
CGRect rect=[UIScreen mainScreen].applicationFrame;
//開始畫圓
/*
@param Center 圓中心點
@param radius 半徑
@param startAngle 開始角度
@param endAngle 結束角度
@param clockwise 是否順時鐘
@param Center 圓中心點
@param radius 半徑
@param startAngle 開始角度
@param endAngle 結束角度
@param clockwise 是否順時鐘
*/
[path addArcWithCenter:CGPointMake(rect.size.width/2,rect.size.height/2-20) radius:100 startAngle:DEGREES_TO_RADIANS(-90)
endAngle:DEGREES_TO_RADIANS(270) clockwise:YES];
arcLayer=[CAShapeLayer layer];
arcLayer.path=path.CGPath;
//填滿顏色
arcLayer.fillColor = [UIColor clearColor].CGColor;
//線段顏色
arcLayer.strokeColor=[UIColor redColor].CGColor;
//線段寬度
arcLayer.lineWidth=3;
arcLayer.frame=self.view.frame;
[self.view.layer addSublayer:arcLayer];
[self drawLineAnimation:arcLayer];
}
//定義動畫
-(void)drawLineAnimation:(CALayer*)layer
{
CABasicAnimation *bas=[CABasicAnimation animationWithKeyPath:@"strokeEnd"];
bas.duration=10;
bas.delegate=self;
bas.repeatCount = CGFLOAT_MAX;
bas.fromValue=[NSNumber numberWithInteger:0];
bas.toValue=[NSNumber numberWithInteger:1];
bas.byValue=[NSNumber numberWithInteger:0.1];
[layer addAnimation:bas forKey:@"key"];
arcLayer=[CAShapeLayer layer];
arcLayer.path=path.CGPath;
//填滿顏色
arcLayer.fillColor = [UIColor clearColor].CGColor;
//線段顏色
arcLayer.strokeColor=[UIColor redColor].CGColor;
//線段寬度
arcLayer.lineWidth=3;
arcLayer.frame=self.view.frame;
[self.view.layer addSublayer:arcLayer];
[self drawLineAnimation:arcLayer];
}
//定義動畫
-(void)drawLineAnimation:(CALayer*)layer
{
CABasicAnimation *bas=[CABasicAnimation animationWithKeyPath:@"strokeEnd"];
bas.duration=10;
bas.delegate=self;
bas.repeatCount = CGFLOAT_MAX;
bas.fromValue=[NSNumber numberWithInteger:0];
bas.toValue=[NSNumber numberWithInteger:1];
bas.byValue=[NSNumber numberWithInteger:0.1];
[layer addAnimation:bas forKey:@"key"];
}
文章標籤
全站熱搜