IOS animation programming 1-affine transformation

Source: Internet
Author: User

IOS animation programming 1-affine transformation

In essence, affine transformation is a matrix transformation that can be used for operations such as translation, scaling, and rotation.

These operations can be encapsulated into animations.

 

1. Definition of apple's official documentation:

 

 

CGAffineTransform CGAffineTransformMake ( CGFloat a, CGFloat b, CGFloat c, CGFloat d, CGFloat tx, CGFloat ty );ParametersaThe value at position [1,1] in the matrix.bThe value at position [1,2] in the matrix.cThe value at position [2,1] in the matrix.dThe value at position [2,2] in the matrix.txThe value at position [3,1] in the matrix.tyThe value at position [3,2] in the matrix.

 

(A, B, c, d, tx, ty) is a transform consisting of the following six numbers:

Tx, ty is actually the position of the view in the view. We can change it for the translation operation.

The corresponding matrix table view is as follows:


 

2. Several ways to create a transform

Pass

 

CGAffineTransformMake (native matrix) CGAffineTransformMakeRotation (rotation) CGAffineTransformMakeScale (scaling) CGAffineTransformMakeTranslation (Translation)

 

 

These methods can create an affine transform.

3. Change several transform Methods

Pass

(1) Perform a translation operation on the basis of the original transform. The returned value is the new transform.

 

CGAffineTransformTranslate ( CGAffineTransform t, CGFloat tx, CGFloat ty );ParameterstAn existing affine transform.txThe value by which to move x values with the affine transform.tyThe value by which to move y values with the affine transform.Return ValueA new affine transformation matrix.
(2) scale based on the original one and 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 which to scale y values of the affine transform.
(3) rotate on the original basis. Note that the rotation angle is a 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) Reverse the previous transform (Inverse Operation)
CGAffineTransformInvert ( CGAffineTransform t );ParameterstAn existing affine transform.Return ValueA new affine transformation matrix. If the affine transform passed in parameter t cannot be inverted, Quartz returns the affine transform unchanged.
(5) merge two transforms and combine the two transforms.

 

 

CGAffineTransformConcat ( CGAffineTransform t1, CGAffineTransform t2 );Parameterst1The first affine transform.t2The second affine transform. This affine transform is concatenated to the first affine transform.Return ValueA new affine transformation matrix. That is, t’ = t1*t2.
4. Apply the transform, such as CGPoint, CGSize, and CGRect, to directly apply the transform to perform corresponding matrix operations.

 

 

 

(1) CGPointApplyAffineTransform (CGPoint point, CGAffineTransform t); (points after the resolution are obtained ..) ParameterspointA point that 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 that 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.

For example, perform a translation operation on a vertex to obtain a new vertex.

 

CGPoint pp = CGPointMake (100,100); CGAffineTransform pingyi = CGAffineTransformMakeTranslation (100, 0); CGPoint newPP = CGPointApplyAffineTransform (pp, pingyi ); // perform the NSLog (@ "the coordinate of the converted vertex is % @", NSStringFromCGPoint (newPP) for the point ));


 

5. Judge transform

 

bool CGAffineTransformIsIdentity ( CGAffineTransform t );ParameterstThe affine transform to check.Return ValueReturns true if t is the identity transform, false otherwise.
(1) check whether a Transform is a constant transformation, that is, it remains 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) compare whether two transforms are equal

6. transform Animation

 

After a transform is set, the rest is added to the UIView animation for execution.

 

CGAffineTransform tt = CGAffineTransformMakeScale(0.5, 0.5);    [UIView animateWithDuration:1 animations:^{        view1.transform = tt;    }];
We need to use the transform attribute of UIView.
Other operations are similar. Of course we can combine these transform ()

 

 

CGAffineTransformConcat
The preceding method can be used to merge two transforms.

 

More articles: http://blog.csdn.net/yangbingbinga

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.