iOS开发中使用Quartz2D绘制上下文栈和矩阵的方法
上下文栈
一、qurza2d是怎么将绘图信息和绘图的属性绘制到图形上下文中去的?
说明:
新建一个项目,自定义一个view类和storyboard关联后,重写该类中的drowrect方法。
画线的三个步骤:
(1)获取上下文
(2)绘图
(3)渲染
要求:画两条单独的线
代码和效果图:
-(void)drawRect:(CGRect)rect
{
//获取上下文
CGContextRefctx=UIGraphicsGetCurrentContext();
//绘图
//第一条线
CGContextMoveToPoint(ctx,20,100);
CGContextAddLineToPoint(ctx,100,320);
//第二条线
CGContextMoveToPoint(ctx,40,200);
CGContextAddLineToPoint(ctx,80,100);
//渲染
CGContextStrokePath(ctx);
}