单军华
2016-12-21 8329ef237d1841d377718813a0b452ea0df64378
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
//  JHPieItemsView.m
//  JHCALayer
//
//  Created by cjatech-简豪 on 16/4/28.
//  Copyright © 2016年 JH. All rights reserved.
//
 
#import "JHPieItemsView.h"
@interface JHPieItemsView ()
 
@property (nonatomic,assign) CGFloat beginAngle;
@property (nonatomic,assign) CGFloat endAngle;
@property (nonatomic,strong) UIColor * fillColor;
@property (nonatomic,strong) CAShapeLayer * shapeLayer;
@end
@implementation JHPieItemsView
-(JHPieItemsView *)initWithFrame:(CGRect)frame andBeginAngle:(CGFloat)beginAngle andEndAngle:(CGFloat)endAngle andFillColor:(UIColor *)fillColor{
    
    if (self = [super initWithFrame:frame]) {
        
        
        _beginAngle = beginAngle;
        _endAngle = endAngle;
        _fillColor = fillColor;
        
        [self configBaseLayer];
        
    }
    
    return self;
    
    
    
}
 
- (void)configBaseLayer{
    _shapeLayer = [CAShapeLayer layer];
 
    UIBezierPath *path = [UIBezierPath bezierPath];
    
    [path addArcWithCenter:CGPointMake(self.frame.size.width/2, self.frame.size.height/2) radius:self.frame.size.width/2 startAngle:_beginAngle endAngle:_endAngle clockwise:YES];
    
    _shapeLayer.path = path.CGPath;
    _shapeLayer.lineWidth = self.frame.size.width;
    _shapeLayer.strokeColor = _fillColor.CGColor;
    _shapeLayer.fillColor = [UIColor clearColor].CGColor;
 
    
    [self.layer addSublayer:_shapeLayer];
    
    CABasicAnimation *basic = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    basic.duration = 1.1;
    basic.fromValue = @(0.1f);
    basic.toValue = @(1.0f);
    [_shapeLayer addAnimation:basic forKey:@"basic"];
    
    
}
 
 
 
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    NSLog(@"touch%ld",self.tag);
    
}
 
@end