close

#define   DEGREES_TO_RADIANS(degrees)  ((pi * degrees)/ 180)

 
//初始化Layer
-(
void)intiUIOfView
{
   
UIBezierPath *path=[UIBezierPath bezierPath];
   
CGRect rect=[UIScreen mainScreen].applicationFrame;
   
//開始畫圓

   
/*
     @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"];
}
arrow
arrow
    文章標籤
    UIBezierPath iOS Objective-C
    全站熱搜
    創作者介紹
    創作者 Mr.Lin 的頭像
    Mr.Lin

    Mr.Lin

    Mr.Lin 發表在 痞客邦 留言(0) 人氣()