ios图形之矩阵操作

 1 - (void)drawRect:(CGRect)rect
 2 {
 3     // 画四边形
 4     CGContextRef ctx = UIGraphicsGetCurrentContext();
 5     
 6     // 保存上下文
 7     CGContextSaveGState(ctx);
 8     
 9     // 注意:设置矩阵操作必须在添加绘图信息之前
10     CGContextRotateCTM(ctx, M_PI_4);
11 //    CGContextScaleCTM(ctx, 0.5, 0.5);
12 //    CGContextTranslateCTM(ctx, 0, 150);
13     
14     CGContextAddRect(ctx, CGRectMake(200, 100, 100, 100));
15     
16     
17     CGContextRestoreGState(ctx);
18     
19     CGContextAddEllipseInRect(ctx, CGRectMake(20, 20, 100, 100));
20     
21     CGContextStrokePath(ctx);
22     
23 }

posted @ 2016-01-22 22:02  xiaocaoera  阅读(418)  评论(0编辑  收藏  举报