Liang's Blog

Dont worry,be happy.

Draw Circle

| Comments

核心英雄

1
PopAnimation CAShapeLayer kPOPShapeLayerStrokeEnd

使用CAShapeLayer与UIBezierPath画出想要的图形(http://blog.csdn.net/volcan1987/article/details/9969455)

1
2
3
4
1、新建UIBezierPath对象bezierPath
2、新建CAShapeLayer对象caShapeLayer
3、将bezierPath的CGPath赋值给caShapeLayer的path,即caShapeLayer.path = bezierPath.CGPath
4、把caShapeLayer添加到某个显示该图形的layer中

下边代码完成了绘制一个圆圈,使用动画的方式呈现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    self.circle = [CAShapeLayer layer];
    self.circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(location.x - radius,
                                                                          location.y - radius,
                                                                          radius*2,
                                                                          radius*2)
                                                  cornerRadius:radius].CGPath;
    
    // Configure the apperence of the circle
    self.circle.fillColor = [UIColor clearColor].CGColor;
    self.circle.strokeColor = [UIColor whiteColor].CGColor;
    self.circle.lineWidth = 2;
    self.circle.strokeEnd = 0.0;
    
    // Add to parent layer
    [self.layer addSublayer:self.circle];
    
    POPBasicAnimation *draw = [POPBasicAnimation animationWithPropertyNamed:kPOPShapeLayerStrokeEnd];
    draw.fromValue = @(0.0);
    draw.toValue = @(1.0);
    draw.duration = 0.8;
    draw.delegate = self;
    [draw setValue:@"draw" forKey:@"animName"];
    draw.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    [self.circle pop_addAnimation:draw forKey:@"draw"];

代码来源 https://github.com/iBaro/PopPlayground

原创作品,转载请注明出处,谢谢。

Comments