CoreGraphics中的 CGAffineTransform的讲解

1对于 CoreGraphics 框架,是绘制平面图形时所需的框架与 Foundation 框架,UIKit 框架为项目创建时默认提供的3大框架。

2  对于CGAffineTransform 的描述,apple 官方文档是这样描述的:

The CGAffineTransform data structure represents a matrix used for affine transformations. A transformation specifies how points in one coordinate system map to points in another coordinate system. An affine transformation is a special type of mapping that preserves parallel lines in a path but does not necessarily preserve lengths or angles. Scaling, rotation, and translation are the most commonly used manipulations supported by affine transforms, but skewing is also possible.

翻译如下:CGAffineTransform这种数据结构表示了一个用于仿射变换(http://baike.baidu.com/view/954621.htm?fr=aladdin)的矩阵(http://baike.baidu.com/subview/10337/6436981.htm?fr=aladdin)。一种变换指定了坐标系中的一点的位置如何从 A 坐标系放射到 B 坐标系。仿射变换是一种特殊类型的变换,它可以保存平行线的路径但是不保存长度或角度。缩放,旋转,平移是仿射变换中最常见的操作,倾斜也是支持的。

Quartz provides functions that create, concatenate, and apply affine transformations using the CGAffineTransform data structure. For information on how to use affine transformation functions, see Quartz 2D Programming Guide.

翻译如下:Quartz提供了创建,连接的函数,应用仿射变换时使用CGAffineTransform数据结构,关于仿射变换更多的信息请参考Quartz 2D Programming Guide.

You typically do not need to create an affine transform directly—CGContext Reference describes functions that modify the current affine transform. If you don’t plan to reuse an affine transform, you may want to use CGContextScaleCTMCGContextRotateCTM,CGContextTranslateCTM, or CGContextConcatCTM.

翻译如下:你通常不需要直接创建一个仿射变换, CGContext Reference描述了如何修改当前变换的函数。如果你不打算重用这个仿射变换,你可以使用

CGContextScaleCTMCGContextRotateCTM,CGContextTranslateCTM, or CGContextConcatCTM.

3:相关说明

struct CGAffineTransform {

  CGFloat a, b, c, d;

  CGFloat tx, ty;

};首先这是一个结构体,包括6个浮点型的变量 a,b,c,d,tx,ty。其实它们是一个3行3列矩阵(matrix)的前2列的元素,最后一列默认为

(0

  0

 1)其位置描述苹果是这样描述的

Parameters
a

The value at position [1,1] in the matrix.

b

The value at position [1,2] in the matrix.

c

The value at position [2,1] in the matrix.

d

The value at position [2,2] in the matrix.

tx

The value at position [3,1] in the matrix.

ty

The value at position [3,2] in the matrix.

最终由这9个参数构成了一个3行3列的矩阵
 |   a, b,  0  |
 |   c, d,  0  |
 |  tx, ty,1    |

a: Creating an Affine Transformation Matrix(创建一个仿射变换矩阵)
  • Returns an affine transformation matrix constructed from values you provide.(根据你提供的值返回一个仿射矩阵)

    Declaration

    OBJECTIVE-C

    CGAffineTransform CGAffineTransformMake ( CGFloat a, CGFloat b, CGFloat c, CGFloat d, CGFloat tx, CGFloat ty );

    Return Value

    A new affine transform matrix constructed from the values you specify.(根据你指定的值构建一个新的仿射矩阵)

    Discussion

    This function creates a CGAffineTransform structure that represents a new affine transformation matrix, which you can use (and reuse, if you want) to transform a coordinate system. The matrix takes the following form:

    image: ../Art/equation01.pict

    Because the third column is always (0,0,1), the CGAffineTransform data structure returned by this function contains values for only the first two columns.(这个函数创建了一个CGAffineTransform结构变量,用于表示一个新的仿射变换矩阵,你可以使用它在坐标系统中变换你想改变的视图,矩阵的形式如下)


    其中b,c,d 这三种情况都以系统默认的 transform 为基准,默认的 transform 为(1,0,1,0,0,0)。即视图最初在的布局位置

b: CGAffineTransformMakeRotation (用于旋转的函数)

Returns an affine transformation matrix constructed from a rotation value you provide.

Declaration

SWIFT

func CGAffineTransformMakeRotation(_ angleCGFloat) -> CGAffineTransform

OBJECTIVE-C

CGAffineTransform CGAffineTransformMakeRotation ( CGFloat angle );

Parameters
angle

The angle, in radians, by which this matrix rotates the coordinate system axes. In iOS, a positive value specifies counterclockwise rotation and a negative value specifies clockwise rotation. In OS X, a positive value specifies clockwise rotation and a negative value specifies counterclockwise rotation.(对于参数的解释:这个角度(弧度表示),通过这个参数决定在坐标系统中旋转的程度及旋转方向,在IOS,正值指定逆时针旋转和负值指定为顺时针方向旋转。在OS X中,一个正值指定为顺时针方向旋转,而负值指定逆时针旋转。)

Return Value

A new affine transformation matrix.








This function creates a CGAffineTransform structure, which you can use (and reuse, if you want) to rotate a coordinate system. The matrix takes the following form:

image: ../Art/equation10.pict

The actual direction of rotation is dependent on the coordinate system orientation of the target platform, which is different in iOS and OS X. Because the third column is always (0,0,1), the CGAffineTransform data structure returned by this function contains values for only the first two columns.旋转的实际方向取决于目标平台的坐标系统取向,在iOS和OS X是不同的。坐标系的第三列是永远(0,0,1),这个函数返回的CGAffineTransform数据结构包含的值只有头两列。

These are the resulting equations that Quartz uses to apply the rotation to a point (x, y): (Quartz将使用如下的方程组对点(x,y)重新布局)

image: ../Art/equation11.pict  ()

c:CGAffineTransformMakeScale(用于缩放的函数)

Returns an affine transformation matrix constructed from scaling values you provide.

Declaration



















SWIFT

func CGAffineTransformMakeScale(_ sxCGFloat,
                              _ syCGFloat) -> CGAffineTransform

OBJECTIVE-C




CGAffineTransform CGAffineTransformMakeScale ( CGFloat sx, CGFloat sy );

Parameters
sx

The factor by which to scale the x-axis of the coordinate system.(sx将用于缩放坐标系 X 轴上的点)

sy

The factor by which to scale the y-axis of the coordinate system. (sy将用于缩放坐标系Y 轴上的点)

Return Value

A new affine transformation matrix.

Discussion

This function creates a CGAffineTransform structure, which you can use (and reuse, if you want) to scale a coordinate system. The matrix takes the following form:

image: ../Art/equation08.pict

Because the third column is always (0,0,1), the CGAffineTransform data structure returned by this function contains values for only the first two columns.

These are the resulting equations that Quartz uses to scale the coordinates of a point (x,y):

image: ../Art/equation09.pict



d:
CGAffineTransformMakeTranslation(用于平移的函数)

Returns an affine transformation matrix constructed from translation values you provide.

Declaration

SWIFT

func CGAffineTransformMakeTranslation(_ txCGFloat,
                                    _ tyCGFloat) -> CGAffineTransform

OBJECTIVE-C

CGAffineTransform CGAffineTransformMakeTranslation ( CGFloat tx, CGFloat ty );

Parameters
tx

The value by which to move the x-axis of the coordinate system.(这个参数决定了在 X 轴上的移动)

ty

The value by which to move the y-axis of the coordinate system.(这个参数决定了在 Y 轴上的移动)

Return Value

A new affine transform matrix.

Discussion

This function creates a CGAffineTransform structure. which you can use (and reuse, if you want) to move a coordinate system. The matrix takes the following form:

image: ../Art/equation06.pict

Because the third column is always (0,0,1), the CGAffineTransform data structure returned by this function contains values for only the first two columns.

These are the resulting equations Quartz uses to apply the translation to a point (x,y):

image: ../Art/equation07.pict

e:CGAffineTransformTranslate(根据指定的Transform再做平移变换,与 CGAffineTransformMakeTanslate 其他相同)
Declaration

SWIFT

func CGAffineTransformTranslate(_ tCGAffineTransform,
                              _ txCGFloat,
                              _ tyCGFloat) -> CGAffineTransform

OBJECTIVE-C

CGAffineTransform CGAffineTransformTranslate ( CGAffineTransform t, CGFloat tx, CGFloat ty );


t

An existing affine transform.

tx

The value by which to move x values with the affine transform.

ty

The value by which to move y values with the affine transform.


f:( 根据指定的 transform 进行缩放 )

SWIFT

func CGAffineTransformScale(_ tCGAffineTransform,
                          _ sxCGFloat,
                          _ syCGFloat) -> CGAffineTransform

OBJECTIVE-C

CGAffineTransform CGAffineTransformScale ( CGAffineTransform t, CGFloat sx, CGFloat sy );

Parameters
t

An existing affine transform.

sx

The value by which to scale x values of the affine transform.

sy

The value by which to scale y values of the affine transform.

g:(根据指定的 transform 进行旋转
Declaration

SWIFT

func CGAffineTransformRotate(_ tCGAffineTransform,
                           _ angleCGFloat) -> CGAffineTransform

OBJECTIVE-C

CGAffineTransform CGAffineTransformRotate ( CGAffineTransform t, CGFloat angle );

Parameters
t

An existing affine transform.

angle

The angle, in radians, by which to rotate the affine transform. In iOS, a positive value specifies counterclockwise rotation and a negative value specifies clockwise rotation. In OS X, a positive value specifies clockwise rotation and a negative value specifies counterclockwise rotation.

h:( 关于 CGAffineTransform的详细信息
  • A structure for holding an affine transformation matrix.

    Declaration

    OBJECTIVE-C

    struct CGAffineTransform { CGFloat a; CGFloat b; CGFloat c; CGFloat d; CGFloat tx; CGFloat ty; }; typedef structCGAffineTransform CGAffineTransform;

    Fields
    a

    The entry at position [1,1] in the matrix.

    b

    The entry at position [1,2] in the matrix.

    c

    The entry at position [2,1] in the matrix.

    d

    The entry at position [2,2] in the matrix.

    tx

    The entry at position [3,1] in the matrix.

    ty

    The entry at position [3,2] in the matrix.

    Discussion

    In Quartz 2D, an affine transformation matrix is used to rotate, scale, translate, or skew the objects you draw in a graphics context. TheCGAffineTransform type provides functions for creating, concatenating, and applying affine transformations.

    In Quartz, affine transforms are represented by a 3 by 3 matrix:

    image: ../Art/equation01.pict

    Because the third column is always (0,0,1), the CGAffineTransform data structure contains values for only the first two columns.

    Conceptually, a Quartz affine transform multiplies a row vector representing each point (x,y) in your drawing by this matrix, producing a vector that represents the corresponding point (x’,y’):

    image: ../Art/equation02.pict

    Given the 3 by 3 matrix, Quartz uses the following equations to transform a point (x, y) in one coordinate system into a resultant point (x’,y’) in another coordinate system.

    image: ../Art/equation03.pict

    The matrix thereby “links” two coordinate systems—it specifies how points in one coordinate system map to points in another.

    Note that you do not typically need to create affine transforms directly. If you want only to draw an object that is scaled or rotated, for example, it is not necessary to construct an affine transform to do so. The most direct way to manipulate your drawing—whether by movement, scaling, or rotation—is to call the functions CGContextTranslateCTMCGContextScaleCTM, or CGContextRotateCTM, respectively. You should generally only create an affine transform if you want to reuse it later.


Constants

  • The identity transform.

    Declaration

    SWIFT

    let CGAffineTransformIdentity: CGAffineTransform

    OBJECTIVE-C

    constCGAffineTransformCGAffineTransformIdentity;

    Constants
    • CGAffineTransformIdentity

      The identity transform:image: ../Art/equation04.gif







  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: ASP.NET Core 3.1是一个跨平台、高性能的开源框架,它可以帮助我们快速地构建Web应用程序。ASP.NET Core 3.1文教程可以为初学者提供一个快速上手的指南,帮助他们了解和掌握该框架的各种功能。 在学习ASP.NET Core 3.1教程之前,我们需要了解一些基本的编程概念和技能, 包括C#语言的基础知识、MVC(Model View Controller)等常见的编程模式、以及前端技术如HTML、CSS和JavaScript等。此外,我们还需要对.NET Core框架有一定的了解,如.NET Core的概念、架构和基础组件等。 学习ASP.NET Core 3.1的教程需要深入理解其设计方案和特点,例如跨平台、高性能、依赖注入、实时通信等。此外,我们还需要熟悉其主要组件,如ASP.NET Core间件、MVC框架、Entity Framework Core等。 在学习ASP.NET Core 3.1的教程时,我们需要通过实践才能更好地理解其所涉及的技术和概念。因此,我们需要通过编写各种实际的Web应用程序和示例,来实践和掌握所学的技巧和知识。 总之,学习ASP.NET Core 3.1的文教程需要较深的前置知识储备和实操经验,而且需要坚持不懈地学习和练习以提高自己的技能水平。 ### 回答2: ASP.NET Core 3.1是目前为止最新的ASP.NET Core版本,它是一个跨平台的Web应用程序开发框架。对于想要学习ASP.NET Core 3.1的开发者来说,文教程是非常重要的。 现在,有很多文教程可以帮助开发者快速入门ASP.NET Core 3.1。这些教程通常包括以下内容: 1. ASP.NET Core 3.1的基础知识:网页处理、路由、控制器等; 2. ASP.NET Core 3.1的模型、视图和控制器; 3. 动作过滤器和特性; 4. 实体框架和数据库相关操作; 5. API设计和测试等。 这些教程通常包含实例和练习,能够帮助开发者深入理解ASP.NET Core 3.1的开发原理。另外,一些知名的在线教育平台,如网易云课堂等,也提供了ASP.NET Core 3.1的文课程,有兴趣的开发者可以去尝试。 总的来说,学习ASP.NET Core 3.1需要投入时间和精力,但是文教程能够让初学者更加轻松地掌握ASP.NET Core 3.1的开发技能,更好地进行ASP.NET Core 3.1的开发工作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值