iOS开发之Quarz2D:九:图形上下文矩阵操作

#import "VCView.h"

@implementation VCView


- (void)drawRect:(CGRect)rect {
    // Drawing code
    
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 100, 50)];
    
    //平移操作
    CGContextTranslateCTM(ctx, 100, 100);
    //旋转
    CGContextRotateCTM(ctx, M_PI_4);
    //缩放
    CGContextScaleCTM(ctx, 1.5, 1.5);
    
  
    CGContextAddPath(ctx, path.CGPath);
    
    [[UIColor redColor] set];
    CGContextFillPath(ctx);
    
    
}


@end

上下文的矩阵操作其实就是修改上下文的形变,

  主要有以下几种

  平移

  CGContextTranslateCTM(ctx, 100, 100);

  旋转

  CGContextRotateCTM(ctx, M_2_PI);

  缩放

  CGContextScaleCTM(ctx, 0.5, 0.5);

  注意:上下文操作必须得要在添加路径之前去设置

原文地址:https://www.cnblogs.com/cqb-learner/p/5821840.html