上下文的矩阵操作

Posted on 2016-07-12 17:02  柠檬片  阅读(146)  评论(0)    收藏  举报
 1 - (void)drawRect:(CGRect)rect {
 2 
 3     
 4     //1.获得跟View相关联的上下文
 5     CGContextRef ctx =  UIGraphicsGetCurrentContext();
 6     //2.描述路径
 7     UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(-100, -50, 200, 100)];
 8     [[UIColor redColor] set];
 9     
10     //上下文的矩阵操作,必须得要在添加路径之前做操作.
11     //平移
12     CGContextTranslateCTM(ctx, 100, 50);
13     
14     //缩放
15     CGContextScaleCTM(ctx, 0.5, 0.5);
16     
17     //旋转
18     CGContextRotateCTM(ctx, M_PI_4);
19     
20     //3.把路径 添加到当前上下文
21     CGContextAddPath(ctx, path.CGPath);
22     
23 
24     //4.把上下文的内容渲染出来.
25     CGContextFillPath(ctx);
26     
27     
28     
29     
30     
31     
32     
33 }
上下文的矩阵操作