1褪那、效果圖:
函數(shù)代碼:
/**
*? 二次曲線動畫
*/
-(void)secondBeziePathDrawAnimation1
{
//曲線
UIBezierPath *path=[UIBezierPath bezierPath];
//起點
[path moveToPoint:CGPointMake(20, 20)];
//二次曲線
[path addCurveToPoint:CGPointMake(self.frame.size.width-30, 20) controlPoint1:CGPointMake(self.frame.size.width/4., 0) controlPoint2:CGPointMake(120., 120)];
CAShapeLayer *sLayer=[CAShapeLayer layer];
sLayer.fillColor=[UIColor clearColor].CGColor;
//畫筆顏色
sLayer.strokeColor=[UIColor redColor].CGColor;
//畫筆寬度
sLayer.lineWidth=2.f;
//路徑
sLayer.path=path.CGPath;
sLayer.strokeStart=0.5;
sLayer.strokeEnd=.5;
[self.layer addSublayer:sLayer];
//動畫效果
CABasicAnimation *slayerAnimat=[CABasicAnimation animationWithKeyPath:@"strokeStart"];
slayerAnimat.duration=5;
slayerAnimat.fromValue=[NSNumber numberWithFloat:0.5];
slayerAnimat.toValue=[NSNumber numberWithFloat:0.];
slayerAnimat.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
slayerAnimat.fillMode=kCAFillModeForwards;
slayerAnimat.removedOnCompletion=NO;
[sLayer addAnimation:slayerAnimat forKey:@"path"];
//? ? //動畫效果
CABasicAnimation *slayerAnimat1=[CABasicAnimation animationWithKeyPath:@"strokeEnd"];
slayerAnimat1.duration=5;
slayerAnimat1.fromValue=[NSNumber numberWithFloat:0.5];
slayerAnimat1.toValue=[NSNumber numberWithFloat:1];
slayerAnimat1.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
slayerAnimat1.fillMode=kCAFillModeForwards;
slayerAnimat1.removedOnCompletion=NO;
[sLayer addAnimation:slayerAnimat1 forKey:@"path1"];
}
/**
*? 二次曲線線逐漸變粗動畫
*/
-(void)secondBeziePathLineWidthDrawAnimation
{
//曲線
UIBezierPath *path=[UIBezierPath bezierPath];
//起點
[path moveToPoint:CGPointMake(20, 20)];
//二次曲線
[path addCurveToPoint:CGPointMake(self.frame.size.width-30, 20) controlPoint1:CGPointMake(self.frame.size.width/4., 0) controlPoint2:CGPointMake(120., 120)];
CAShapeLayer *sLayer=[CAShapeLayer layer];
sLayer.fillColor=[UIColor clearColor].CGColor;
//畫筆顏色
sLayer.strokeColor=[UIColor redColor].CGColor;
//畫筆寬度
sLayer.lineWidth=2.f;
//路徑
sLayer.path=path.CGPath;
sLayer.strokeStart=0.;
sLayer.strokeEnd=1;
[self.layer addSublayer:sLayer];
//動畫效果
CABasicAnimation *slayerAnimat=[CABasicAnimation animationWithKeyPath:@"strokeEnd"];
slayerAnimat.duration=5;
slayerAnimat.fromValue=[NSNumber numberWithFloat:0.];
slayerAnimat.toValue=[NSNumber numberWithFloat:1.];
slayerAnimat.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
slayerAnimat.fillMode=kCAFillModeForwards;
slayerAnimat.removedOnCompletion=NO;
[sLayer addAnimation:slayerAnimat forKey:@"path"];
//? ? //動畫效果
CABasicAnimation *slayerAnimat1=[CABasicAnimation animationWithKeyPath:@"lineWidth"];
slayerAnimat1.duration=5;
slayerAnimat1.fromValue=[NSNumber numberWithFloat:0];
slayerAnimat1.toValue=[NSNumber numberWithFloat:10];
slayerAnimat1.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
slayerAnimat1.fillMode=kCAFillModeForwards;
slayerAnimat1.removedOnCompletion=NO;
[sLayer addAnimation:slayerAnimat1 forKey:@"path1"];
}
以上教程的所有項目源代碼;https://github.com/fb2012/IOS/tree/master/UIBezierPathStady