ios_画圆代码—so_easy!

来源:互联网 发布:windows桥接虚拟机网卡 编辑:程序博客网 时间:2024/05/29 05:04
//画圆圈
-(void)intiUIOfView
{
    UIBezierPath *path=[UIBezierPath bezierPath];
    
    NSInteger radius  ; // 画圆的弧度
    NSInteger circleHeight; //画圆的y轴便宜量
    if ([UICommon isHotsPot] == YES) {
        
        circleHeight = iPhone5?43:41;
    }else
        
    {
        circleHeight = iPhone5?23:21;
    }
    
    radius = iPhone5?83:71;
    
    if (self.albumCount >= 10)
    {
        [path addArcWithCenter:CGPointMake(self.upBtn.frame.origin.x + self.upBtn.frame.size.width/2,self.upBtn.frame.origin.y +self.upBtn.frame.size.height/2+circleHeight) radius:radius startAngle:1.465*2*M_PI+0.535*M_PI endAngle: 1.465*M_PI  clockwise:NO];
        
    }
    else
    {
        [path addArcWithCenter:CGPointMake(self.upBtn.frame.origin.x + self.upBtn.frame.size.width/2,self.upBtn.frame.origin.y +self.upBtn.frame.size.height/2+circleHeight) radius:radius startAngle:1.54*2*M_PI+0.465*M_PI endAngle: 1.535*M_PI  clockwise:NO];
    }
    
    
    self.arcLayer=[CAShapeLayer layer];
    self.arcLayer.path = path.CGPath;//46,169,230
    self.arcLayer.fillColor  = [UIColor clearColor].CGColor;
    self.arcLayer.lineWidth = 2.0f;
    self.arcLayer.frame = self.frame;
    self.arcLayer.lineCap = kCALineCapRound;//指定线的边缘是圆
    self.arcLayer.lineJoin = kCALineCapRound;//终点处理边缘是圆
    //大于10绘的颜色是红色否则蓝色
    if (self.albumCount >= 10) {
        self.arcLayer.strokeColor = [UIColor getColor:@"fe62a4"].CGColor;
       // self.arcLayer.strokeColor = [UIColor colorWithRed:255.0/255.0 green:85.0/255.0 blue:157.0/255.0 alpha:1].CGColor;
    }
    else
    {
        self.arcLayer.strokeColor = [UIColor getColor:@"00b8bf"].CGColor;

       // self.arcLayer.strokeColor = [UIColor colorWithRed:81.0/255.0 green:194.0/255.0 blue:198.0/255.0 alpha:1].CGColor;
    }
    
    [self.layer addSublayer:self.arcLayer];
    [self drawLineAnimation:self.arcLayer];
    
    
}
-(void)drawLineAnimation:(CALayer*)layer
{
    [NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:@selector(zoomInAndzoomOut:) userInfo:nil repeats:NO];
    
    CABasicAnimation *bas = [CABasicAnimation animationWithKeyPath:@"strokeStart"];
    bas.duration = .8;
    bas.delegate = self;
    bas.fromValue= [NSNumber numberWithInteger:1];
    bas.toValue  = [NSNumber numberWithInteger:0];
    [layer addAnimation:bas forKey:@"key"];
    
    
    /*
     // 组动画
     CAAnimationGroup *groupAnimation = [CAAnimationGroup animation];
     
     groupAnimation.animations = @[bas ];
     //设置组动画的时间
     groupAnimation.duration = 5;
     groupAnimation.fillMode = kCAFillModeForwards;
     groupAnimation.removedOnCompletion = NO;
     
     [layer addAnimation:groupAnimation forKey:nil];
     */
}

0 0
原创粉丝点击