首页 > 其他 > 详细

CAShapeLayer

时间:2015-11-20 14:06:49      阅读:147      评论:0      收藏:0      [点我收藏+]

 

    UIView *showView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];

    [self.view addSubview:showView];

    showView.backgroundColor = [UIColor redColor];

    showView.alpha = 0.5;

    

    

    

    // 贝塞尔曲线(创建一个圆)

    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(100 / 2.f, 100 / 2.f)

                                                        radius:100 / 2.f

                                                    startAngle:0

                                                      endAngle:M_PI * 2

                                                     clockwise:YES];

    

    

    

    // 创建一个shapeLayer

    CAShapeLayer *layer = [CAShapeLayer layer];

    layer.frame         = showView.bounds;                // 与showView的frame一致

    layer.strokeColor   = [UIColor greenColor].CGColor;   // 边缘线的颜色

    layer.fillColor     = [UIColor blueColor].CGColor;   // 闭环填充的颜色

    layer.lineCap       = kCALineCapSquare;               // 边缘线的类型

    layer.path          = path.CGPath;                    // 从贝塞尔曲线获取到形状

    layer.lineWidth     = 4.0f;                           // 线条宽度

    layer.strokeStart   = 0.0f;

 

    // 将layer添加进图层

    [showView.layer addSublayer:layer];

 

    // 给这个layer添加动画效果

    CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];

    pathAnimation.duration = 1.0;

    pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];

    pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];

    [layer addAnimation:pathAnimation forKey:nil];

CAShapeLayer

原文:http://www.cnblogs.com/ganeveryday/p/4980534.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!