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 CGContextScaleCTM
, CGContextRotateCTM
,CGContextTranslateCTM
, or CGContextConcatCTM
.
CGContextScaleCTM
, CGContextRotateCTM
,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. |
-
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:Because the third column is always
(0,0,1)
, theCGAffineTransform
data structure returned by this function contains values for only the first two columns.(这个函数创建了一个CGAffineTransform结构变量,用于表示一个新的仿射变换矩阵,你可以使用它在坐标系统中变换你想改变的视图,矩阵的形式如下)
Returns an affine transformation matrix constructed from a rotation value you provide.
Declaration
SWIFT
func CGAffineTransformMakeRotation(_
angle
: CGFloat) -> 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:
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)重新布局)
()c:CGAffineTransformMakeScale(用于缩放的函数)
Returns an affine transformation matrix constructed from scaling values you provide.
Declaration
SWIFT
func CGAffineTransformMakeScale(_
sx
: CGFloat,
_ sy
: CGFloat) -> CGAffineTransform
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:
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):
CGAffineTransformMakeTranslation(用于平移的函数)
Returns an affine transformation matrix constructed from translation values you provide.
Declaration
SWIFT
func CGAffineTransformMakeTranslation(_
tx
: CGFloat,
_ ty
: CGFloat) -> 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:
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):
e:CGAffineTransformTranslate(根据指定的Transform再做平移变换,与 CGAffineTransformMakeTanslate 其他相同) Declaration
SWIFT
func CGAffineTransformTranslate(_
t
: CGAffineTransform,
_ tx
: CGFloat,
_ ty
: CGFloat) -> 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. |
SWIFT
func CGAffineTransformScale(_
t
: CGAffineTransform,
_ sx
: CGFloat,
_ sy
: CGFloat) -> 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. |
Declaration
SWIFT
func CGAffineTransformRotate(_
t
: CGAffineTransform,
_ angle
: CGFloat) -> 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. |
-
A structure for holding an affine transformation matrix.
Declaration
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. The
CGAffineTransform
type provides functions for creating, concatenating, and applying affine transformations.In Quartz, affine transforms are represented by a 3 by 3 matrix:
Because the third column is always
(0,0,1)
, theCGAffineTransform
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’):
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.
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
CGContextTranslateCTM
,CGContextScaleCTM
, orCGContextRotateCTM
, respectively. You should generally only create an affine transform if you want to reuse it later.
Constants