Quart2 2D绘图
-
Graphics Context 上下文、画布、绘图环境
- Quart2中默认的坐标系统是:原点(0,0)子啊左下角,沿着x轴从左到右坐标值逐渐增大,沿着Y轴从下到上坐标值逐渐增大
- UIGraphicsGetCurrentContext()可以获取当前上下文,类型为CGContextRef
-
坐标系的转换
- CGContextRotateCTM(CGContextRef c, CGFloat angle) 相对原点旋转上下文坐标系
- CGContextTranslateCTM(CGContextRef c, CGFloat tx, CGFloat ty) 相对原点平移上下文坐标系
- CGContextScaleCTM(CGContextRef c, CGFloat sx, CGFloat sy) 缩放上下文坐标系
-
转换坐标系前,使用CGContextSaveGState(CGContextRef c);保存上下文
CGContextRestoreGState(CGContextRef c);恢复上下文
-
UIBezierPath 贝塞尔路径类
-
常用属性
- lineWidth:画笔的宽度
- lineCapStyle:线头的样式
- lineTainStyle:线与线连接时的样式
-
常用方法
- + bezierPath:常用作创建(工厂方法)
- - moveToPoint:将画笔移动到某一点上
- - addLineToPint:添加一条线从画笔当前点到另一点
- - addQuadCureveToPoint:添加一条贝塞尔曲线
- - addArcWithCenter: 添加一条圆弧
- - closePath: 封闭路径
- - removeAllPoints: 移除所有的点
- - fill: 填充路径
- - stroke: 路径描边
-
-
绘图之全局函数
-
构建路径的函数
- CGContextBeginPath() 开始一个新路径
- CGContextMoveToPoint 设置路径的起点
- CGContextClosePath 关闭路径
- CGContextAddPath 添加路径
- CGContextAddLines 添加多线条
- CGContextAddRect 添加矩形
- CGContextAddRects 添加多个矩形
- CGContextAddEllipseInRect 在矩形中添加椭圆
- CGContextAddArc 添加弧线
- CGContextAddArcToPoint 在指定点添加弧线
- CGContextAddCurreToPoint 在指定点添加曲线
-
绘制路径的函数
- CGContextDrawPath 绘制路径
- CGContextFillPath 实心路径
- CGContextFillRect 实心举行
- CGContextFillRects 多个实心矩形
- CGContextFillEllipseInRect 在矩形区域中绘制实心椭圆
- CGContextStrokePath 空心路径
- CGContextStrokeRect 空心矩形
- CGContextStrokeRectWithWidth 使用宽度绘制空心矩形
- CGContextStrokeEllipseInRect 在矩形区域中绘制空心椭圆
-
绘图状态参数
- CGContextSetLineWidth 线条宽度
- CGContextSetBlendMode 混合模式
- CGContextSetShouldAntialias 抗锯齿效果
- CGContextSetLineCap 设置线条收尾点样式
- CGContextSetLineJain 设置线条连接点样式
- CGContextSetLineDash 设置虚线
-