Affine transformation essence is a matrix transformation, can be used to do translation, scaling, rotation and other operations
These operations can be packaged into animations.
The official document definition for 1.apple:
Cgaffinetransform Cgaffinetransformmake (CGFloat A, cgfloat B, CGFloat C, CGFloat D, CGFloat tx, cgfloat ty); Parametersathe value at position [+] in the matrix.bthe value at position [up] in the matrix.cthe value at position [2, 1] In the matrix.dthe value @ position [2,2] in the matrix.txthe value @ position [3,1] in the matrix.tythe value at POS ition [3,2] in the matrix.
(A,b,c,d,tx,ty) is a transform composition that contains the following 6 numbers
Tx,ty is actually the position of the view in the view, we can change it to do the panning operation
The corresponding matrix table views are as follows:
2. Several ways to create transform
Pass
Cgaffinetransformmake ( native matrix) cgaffinetransformmakerotation (rotation) cgaffinetransformmakescale (scaling) Cgaffinetransformmaketranslation (PAN)
These methods can create an affine transformation
3. Several ways to change transform
Pass
(1) on the original transform based on a second translation operation, the return value of the new transform
Cgaffinetransformtranslate (Cgaffinetransform t, cgfloat tx, cgfloat ty); Parameterstan existing affine transform.txthe value by which to move x values and the affine transform.tythe value by whi Ch to move Y values with the affine transform. Return Valuea new affine transformation matrix.
(2) on the original basis to zoom, return a new transform
Cgaffinetransformscale (Cgaffinetransform T, cgfloat SX, CGFloat sy); Parameterstan existing affine transform.sxthe value by which to scale x values of the affine transform.sythe value by whic h to scale y values of the affine transform.
(3) Rotate on the original basis, note that the angle of rotation is the Radian value
Cgaffinetransformrotate (Cgaffinetransform t, cgfloat angle); Parameterstan existing affine transform.anglethe 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.
(4) Transform before reversal (inverse operation)
Cgaffinetransforminvert (Cgaffinetransform t); Parameterstan existing affine transform. Return Valuea new affine transformation matrix. If the affine transform passed in parameter T cannot is inverted, Quartz returns the affine transform unchanged.
(5) Merging two transform and merging two transform together
Cgaffinetransformconcat (cgaffinetransform t1, Cgaffinetransform T2); Parameterst1the first affine transform.t2the second affine transform. This affine transform are concatenated to the first affine transform. Return Valuea new affine transformation matrix. That's, t ' = t1*t2.
4. Apply the transform, for example Cgpoint,cgsize,cgrect can apply the transform directly to the corresponding matrix operation
(1) Cgpointapplyaffinetransform (cgpoint point,cgaffinetransform t);(can get the point after the affine transformation. Under similar) Parameterspointa point, specifies the X-and y-coordinates to transform.tthe affine transform to apply. Return Valuea new Point resulting from applying the specified affine transform to the existing point.
(2) Cgsizeapplyaffinetransform (cgsize size,cgaffinetransform t); Parameterssizea size Specifies the height and width to transform.tthe affine transform to apply. Return Valuea new size resulting from applying the specified affine transform to the existing size.
(3) Cgrectapplyaffinetransform (CGRect rect,cgaffinetransform t); Parametersrectthe rectangle whose corner points you want to transform.tthe affine transform to apply to the RECT parameter . Return valuethe transformed rectangle.
Example, a point is translated to get a new point
Cgpoint pp = cgpointmake (+); Cgaffinetransform Pingyi = cgaffinetransformmaketranslation (0); Cgpoint newpp = Cgpointapplyaffinetransform (PP, Pingyi);//affine transformation of a point NSLog (@ "Point coordinates after translation is %@", Nsstringfromcgpoint (NEWPP));
5. Judging transform
BOOL Cgaffinetransformisidentity (Cgaffinetransform t); Parameterstthe affine transform to check. Return Valuereturns True if T is the identity transform, false otherwise.
(1)detects if a transform is an identity transform, that is, unchanged
BOOL Cgaffinetransformequaltotransform (cgaffinetransform t1, Cgaffinetransform T2); Parameterst1an affine transform.t2an affine transform. Return valuereturns true if T1 and T2 are equal, false otherwise.
(2) Comparison of two transform are equal
6.transform Animation
Set number after a transform, the rest is added to the UIView animation to execute the
Cgaffinetransform TT = Cgaffinetransformmakescale (0.5, 0.5); [UIView animatewithduration:1 animations:^{ view1.transform = TT; }];
We need to use UIView's Transform property
Other operations are similar, of course we can also combine these transform ()
Cgaffinetransformconcat
Use the method above to merge two transform
More articles: Http://blog.csdn.net/yangbingbinga
iOS animation programming 1-Affine transformations