//绘制路径
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(20 ,20.0)];
[path addLineToPoint:CGPointMake(120, 20)];
[path addLineToPoint:CGPointMake(120, 120)];
[path addLineToPoint:CGPointMake(20, 120)];
[path addLineToPoint:CGPointMake(20, 20)];
//图形设置
CAShapeLayer *pathLayer = [CAShapeLayer layer];
pathLayer.frame = self.view.bounds;
pathLayer.path = path.CGPath;
pathLayer.strokeColor = [[UIColor redColor] CGColor];
pathLayer.fillColor = nil;
pathLayer.lineWidth = 4.0f;
pathLayer.lineJoin = kCALineJoinBevel;
[drawView.layer addSublayer:pathLayer];
//动画
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeStart"];
pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeStart"];//strokeend
pathAnimation.duration = 2.0;
pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];
[pathLayer addAnimation:pathAnimation forKey:@"strokeStart"];