IOS_ UIBezierPath + CABasicAnimation + CAShapeLayer

来源:互联网 发布:山西十一选五遗漏数据 编辑:程序博客网 时间:2024/05/16 01:47

    

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

    [self.viewaddSubview:showView];

    showView.backgroundColor = [UIColorredColor];


    UIBezierPath *path = [UIBezierPathbezierPath];

    [path addArcWithCenter:CGPointMake(50,50)radius:45startAngle:0endAngle:kDegreesToRadians(360)clockwise:YES];

    

    

    UIBezierPath *path1 = [UIBezierPathbezierPath];

    [path1 moveToPoint:CGPointMake(10,50)];

    [path1 addLineToPoint:CGPointMake(50,80)];

    [path1 addLineToPoint:CGPointMake(80,10)];

    

    [path appendPath:path1];

    


    CAShapeLayer *checkLayer = [CAShapeLayerlayer];

    checkLayer.path = path.CGPath;

    checkLayer.frame = showView.bounds;

    checkLayer.fillColor = [UIColorclearColor].CGColor;           //填充颜色

    checkLayer.strokeColor = [UIColorwhiteColor].CGColor;     //线条颜色

    checkLayer.lineWidth =3.0;

    checkLayer.lineCap =kCALineCapRound;

    checkLayer.lineJoin =kCALineJoinRound;

    checkLayer.speed =1;                                  //速度

    [showView.layeraddSublayer:checkLayer];

    

    

    CABasicAnimation *checkAnimation = [CABasicAnimationanimationWithKeyPath:@"strokeEnd"];

    checkAnimation.duration =1.3f;

    checkAnimation.fromValue = [NSNumbernumberWithFloat:0];

    checkAnimation.toValue = [NSNumbernumberWithFloat:1.0];

//    checkAnimation.autoreverses = YES;      //动画按原路返回

//    checkAnimation.delegate = self;

//    checkAnimation.repeatCount = MAXFLOAT;    //设置动画次数

//    checkAnimation.repeatDuration = 8;        //设置动画持续时间

    checkAnimation.fillMode =kCAFillModeForwards;

//    checkAnimation.beginTime = CACurrentMediaTime()+2;      //延迟2  CACurrentMediaTime() 为当前动画时间

    [checkLayer addAnimation:checkAnimationforKey:nil];

    

    

0 0
原创粉丝点击