iOS核心动画CoreAnimation系统进阶(赛贝尔曲线绘制火柴人图形)
程序员文章站
2022-04-11 13:19:12
...
通过绘制经典的火柴人图形,练习赛贝尔曲线的绘制
绘制火柴人图形
1.首先绘制圆形
-(void)shaperLayer{
UIBezierPath * path =[UIBezierPath bezierPath];
//首先绘制圆形
[path moveToPoint:CGPointMake(175, 100)];
//addArcWithCenter既可以画圆也可以画弧线
/*
Center:中心点
radius:半径
startAngle:开始角度
endAngle:结束角度
clockwise:是否是顺时针
*/
[path addArcWithCenter:CGPointMake(150, 100) radius:25 startAngle:0 endAngle:2 *M_PI clockwise:YES];
CAShapeLayer * shapeLayer =[CAShapeLayer layer];
shapeLayer.path =path.CGPath;
[self.view.layer addSublayer:shapeLayer];
}
shapeLayer.strokeColor =[UIColor redColor].CGColor;//画笔颜色
shapeLayer.lineWidth = 5;
shapeLayer.fillColor = nil;//填充颜色
圆圈完成。
2.画一个竖线
//重新来个起始点,画竖线
[path moveToPoint:CGPointMake(150, 125)];
//addLineToPoint画线
[path addLineToPoint:CGPointMake(150, 175)];
线画完了。
3.画两条腿
//画腿 第一条
[path addLineToPoint:CGPointMake(125, 225)];
//另外一条
[path moveToPoint:CGPointMake(150, 175)];
[path addLineToPoint:CGPointMake(175, 225)];
腿画完了。
4.画胳膊
//画胳膊
[path moveToPoint:CGPointMake(100, 150)];
[path addLineToPoint:CGPointMake(200, 150)];
完成
完善细节
shapeLayer.lineCap =kCALineCapRound;//设置线的末尾样式
shapeLayer.lineJoin = kCALineJoinRound;//设置两条连线的中间样式
上一篇: java输入与输出
下一篇: iOS 开发实训第十周周报