iOS学习笔记-055.简单矩阵操作

来源:互联网 发布:sql server error 40 编辑:程序博客网 时间:2024/05/18 06:15

  • 简单矩阵操作
    • 一主要方法说明
    • 二代码
    • 三图示

简单矩阵操作

一、主要方法说明

//缩放CGContextScaleCTM(CGContextRef __nullable c,CGFloat sx, CGFloat sy)//平移CGContextTranslateCTM(CGContextRef __nullable c,CGFloat tx, CGFloat ty)//旋转CGContextRotateCTM(CGContextRef __nullable c, CGFloat angle)

二、代码

////  WMView.m//  03_UIView44_矩阵操作////  Created by 杞文明 on 16/4/14.//  Copyright © 2016年 杞文明. All rights reserved.//#import "WMView.h"@implementation WMView// Only override drawRect: if you perform custom drawing.// An empty implementation adversely affects performance during animation.- (void)drawRect:(CGRect)rect {    //1. 获取上下文    CGContextRef ctx = UIGraphicsGetCurrentContext();    //----------矩阵操作------    //注意:设置矩阵操作必须在添加绘图信息之前    CGContextRotateCTM(ctx, M_PI_4);    CGContextScaleCTM(ctx, 0.9, 1.1);    CGContextTranslateCTM(ctx, 10, 20);    //2. 绘制    CGContextAddEllipseInRect(ctx, CGRectMake(10, 1, 60, 60));    CGContextAddRect(ctx, CGRectMake(100, 1, 80, 40));    //3. 渲染    CGContextStrokePath(ctx);}@end

三、图示

这里写图片描述

0 0
原创粉丝点击