iOS动态绘制曲线

来源:互联网 发布:互联网数据开发是什么 编辑:程序博客网 时间:2024/04/30 14:21

//绘制路径

   UIBezierPath *path =[UIBezierPathbezierPath];

    [pathmoveToPoint:CGPointMake(20,20.0)];

    [pathaddLineToPoint:CGPointMake(120,20)];

    [pathaddLineToPoint:CGPointMake(120,120)];

    [pathaddLineToPoint:CGPointMake(20,120)];

    [pathaddLineToPoint:CGPointMake(20,20)];

   

   //图形设置

   CAShapeLayer *pathLayer =[CAShapeLayerlayer];

   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.layeraddSublayer:pathLayer];

   

   //动画

   CABasicAnimation *pathAnimation =[CABasicAnimationanimationWithKeyPath:@"strokeStart"];

    pathAnimation =[CABasicAnimationanimationWithKeyPath:@"strokeStart"];//strokeend

   pathAnimation.duration =2.0;

   pathAnimation.fromValue =[NSNumbernumberWithFloat:0.0f];

   pathAnimation.toValue =[NSNumbernumberWithFloat:1.0f];

    [pathLayeraddAnimation:pathAnimationforKey:@"strokeStart"];

0 0
原创粉丝点击